试图从数组中获取id

时间:2014-01-06 13:22:30

标签: php json xbmc

这就是我如何获得下面的数组。

$moviess = VideoLibrary::getMovies(

        array("properties" => array()
        ));

array(275) { [0]=> object(stdClass)#68 (2) { ["label"]=> string(16) "2 Fast 2 Furious" ["movieid"]=> int(1) } 
             [1]=> object(stdClass)#351 (2) { ["label"]=> string(6) "2 Guns" ["movieid"]=> int(2) }
             [2]=> object(stdClass)#352 (2) { ["label"]=> string(12) "3:10 to Yuma" ["movieid"]=> int(12) }
             [3]=> object(stdClass)#353 (2) { ["label"]=> string(1) "9" ["movieid"]=> int(3) }
             [4]=> object(stdClass)#354 (2) { ["label"]=> string(9) "10,000 BC" ["movieid"]=> int(4) 

我试图从该数组中检索movieid

将其添加到下面的代码中

$indexdetails = VideoLibrary::getMovieDetails({**I NEED THE movieID HERE FROM THAT ARRAY**}, array(
            'title',
            'genre',
            'year',
            'rating',
            'tagline',
            'plot',
            'mpaa',
            'cast',
            'imdbnumber',
            'runtime',
            'streamdetails',
            'votes',
            'thumbnail',
            'trailer',
            'file',
            'playcount'

        ));

<小时/> 这种作品:

$movies = VideoLibrary::getMovies($requestParameters);
foreach($movies as $mv)
{
    $indexdetails = VideoLibrary::getMovieDetails($mv->movieid, array(
        'title',
    ));

    var_dump($indexdetails);
}

但是当我尝试echo $mv->title;时,我得到了错误。当我尝试$mv['title']时,我得到了不同的东西:

  

PHP致命错误:无法使用stdClass类型的对象作为数组

1 个答案:

答案 0 :(得分:0)

从它的外观来看,你可能会这样做:

$movieDetails = array();
foreach ($moviess as $movie) {
    $movieDetails[$movie->movieid] = VideoLibrary::getMovieDetails(
        $movie->movieid,
        array(
            // ...
        )
    );

    echo $movieDetails[$movie->movieid]->title;
}