-7

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
        )

)
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132

2 Answers2

1

You can access elements inside a stdClass like this:

foreach ($test as $v) {
    echo $v->file;
    echo $v->label;
}
Neil
  • 13,713
  • 3
  • 27
  • 50
0

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);
Ave
  • 4,106
  • 3
  • 37
  • 66