[英]How can I get a specific value in this PHP array?
I'm setting up a Cloudinary listing of uploaded videos and I want to get the metadata of that video.我正在设置上传视频的 Cloudinary 列表,我想获取该视频的元数据。
I have a print_r($result)
:我有一个
print_r($result)
:
<pre>
Cloudinary\Api\Response Object
(
[rate_limit_reset_at] => 123123123
[rate_limit_allowed] => 123
[rate_limit_remaining] => 123
[storage:ArrayObject:private] => Array
(
[public_id] => dog
[format] => mp4
[version] => 123123123
[resource_type] => video
[type] => upload
[created_at] => 2019-07-29T07:32:50Z
[bytes] => 123123
[width] => 321
[height] => 456
[backup] => 1
[access_mode] => public
[url] => http://res.cloudinary.com/demo/video/upload/dog.mp4
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.mp4
[next_cursor] => 123123123
[derived] => Array
(
[0] => Array
(
[transformation] => /jpg
[format] => jpg
[bytes] => 86438
[id] => 123123123
[url] => http://res.cloudinary.com//demo/video/upload/dog.jpg
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.mp4
[extension] => jpg
)
[1] => Array
(
[transformation] => t_media_lib_thumb/jpg
[format] => jpg
[bytes] => 3293
[id] => 12123123
[url] => https://res.cloudinary.com/demo/video/upload/dog.jpg
[secure_url] => https://res.cloudinary.com/demo/video/upload/dog.jpg
[extension] => jpg
)
)
)
)
</pre>
I tried getting the value using this format but it says undefined index.我尝试使用这种格式获取值,但它显示未定义的索引。
echo $result[4]['width']
or echo $result['storage:ArrayObject:private']['width'];
echo $result[4]['width']
或echo $result['storage:ArrayObject:private']['width'];
I talked to a cloudinary support ad he said that "you should be able to access the data returned within [storage:ArrayObject:private] by simply ignoring it and requesting the index that you desire directly from $result. Meaning you can use or and so on with the other paramters."我和一个 cloudinary 支持广告谈过,他说“你应该能够通过简单地忽略它并直接从 $result 请求你想要的索引来访问 [storage:ArrayObject:private] 中返回的数据。这意味着你可以使用或和其他参数依此类推。”
So basically, just removing the index solved my problem like so:所以基本上,只需删除索引就可以解决我的问题,如下所示:
<?php echo $result['height']; ?> <?php echo $result['width']; ?>
Have a look at this https://github.com/cloudinary/cloudinary_php/blob/master/src/Api/Response.php in order to better understand the object you are getting back.看看这个https://github.com/cloudinary/cloudinary_php/blob/master/src/Api/Response.php以便更好地了解您返回的对象。
Afterwards, look at the ArrayObject documentation here https://www.php.net/manual/en/class.arrayobject.php , as your Response object extends this class.之后,在https://www.php.net/manual/en/class.arrayobject.php 中查看 ArrayObject 文档,因为您的 Response 对象扩展了此类。 Using getArrayCopy() to transform your object into an array should be what you need.
使用 getArrayCopy() 将您的对象转换为数组应该是您所需要的。
Bear in mind that I am not familiar with the API and that there may be better options to get what you need.请记住,我不熟悉 API,并且可能有更好的选择来获得您需要的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.