How to get value based on different value from object / array in php

My first question is here after you enjoy the questions and answers of other nations. Thanks for this:)

I try to work with vimeo api, and I get an answer that I can not understand, as I assume. I think it’s just for some of you guys, but I can’t wrap my head around me.

I have a bunch of video id for which I need a thumbnail url. I would like to “ask” the answer “What is the thumb pointer for this identifier” and the loop, although my whole identifier is like that.

The response object is as follows:

stdClass Object
(
    [videos] => stdClass Object
        (
            [video] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 8128888
                            [thumbnails] => stdClass Object
                                (
                                    [thumbnail] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [height] => 75
                                                    [width] => 100
                                                    [_content] => http://ts.vimeo.com.s3.amazonaws.com/370/931/37093137_100.jpg
                                                )
                                        )
                                )
                        )
                    [1] => stdClass Object
                        (
                            [id] => 8760295
                            [thumbnails] => stdClass Object
                                (
                                    [thumbnail] => Array
                                        (
                                            [0] => stdClass Object
                                                (
                                                    [height] => 75
                                                    [width] => 100
                                                    [_content] => http://ts.vimeo.com.s3.amazonaws.com/417/146/41714684_100.jpg
                                                )
                                        )
                                )
                        )
                )
        )
)

I need to use it like this (truncated again), its quoted part, which I cannot determine:

<?php while ( $vid->fetchRecord() ) :
    $vid_id = $vid->get_field('video');
    $thumb = "find [video][thumbnail][0][_content] where [video][id] = $vid_id";
?>
<img src="<?php echo $thumb;?>" 
<?php endwhile ?>

So how close am I ?: P

+3
4

. , $response:

$videos = array();
foreach($response->videos->video as $video) {
  if(count($video->thumbnails->thumbnail) > 0) {
    $videos[$video->id] = $video->thumbnails->thumbnail[0]->_content;
  }
}

$videos id URL:

Array(
  '8128888' => 'http://ts.vimeo.com.s3.amazonaws.com/370/931/37093137_100.jpg',
  '8760295' => 'http://ts.vimeo.com.s3.amazonaws.com/417/146/41714684_100.jpg'
)

:

<?php while ( $vid->fetchRecord() ) :
    $vid_id = $vid->get_field('video');
    $thumb = $videos[$vid_id];
?>
<img src="<?php echo $thumb;?>" 
<?php endwhile ?>
+2
// Assuming the response you posted above is stored in the variable $response

$thumbnails = array ( );

foreach ( $response->videos->video as $vID => $v )
{
        $thumbnails [ $vID ] = $v->thumbnails->thumbnail[0]->_content;
}
+1

, - :

var_dump($responseObject);

, , :

<?php foreach($responseObject->videos->video as $video) { ?>
    <img src="<?= $video->thumbnails->thumbnail[0]->_content?>" />
<?php } ?>

, , while().

0

/ :

// $vid is the object you posted above
foreach( $vid->videos->video as $key => &$video ) {
    echo "id: " . $video->id;
    echo "thumbnails: \n";
    foreach( $video->thumbnails->thumbnail as $key => $thumb ) {
        echo "thumb {$key}: <img src=\" " . $thumb->_content . " \"> \n";
    }
}

, , .

0

Source: https://habr.com/ru/post/1732525/


All Articles