-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,450
  • 15
  • 68
  • 141

2 Answers2

1

You can access elements inside a stdClass like this:

foreach ($test as $v) {
    echo $v->file;
    echo $v->label;
}
Neil
  • 14,063
  • 3
  • 30
  • 51
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,338
  • 4
  • 40
  • 67