如何回显此数组的值? [重复]
问题描述:
This question already has an answer here:
- How can I access an array/object? 4 answers
can someone help me to echo [file] value and [label] value from following array:
Array
(
[0] => stdClass Object
(
[label] => 360p
[type] => video/mp4
[file] => /uploads/myVideo.mp4
[res] => 360p
)
[1] => stdClass Object
(
[label] => 720p
[type] => video/mp4
[file] => /uploads/myVideo.mp4
[res] => 720p
)
[2] => stdClass Object
(
[label] => 480p
[type] => video/mp4
[file] => /uploads/myVideo.mp4
[res] => 480p
)
)
</div>
答
You can foreach
to loop through all item and call in the array like:
foreach($yourArray as $item) {
echo $item->label;
echo $item->file;
}
Or you can be using json_decode
to cast your object to the array.
$result = json_decode($data, true);
答
You can access elements inside a stdClass
like this:
foreach ($test as $v) {
echo $v->file;
echo $v->label;
}