0

I have data like this:

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [name] => xxxxxxxxxxxx
                    [category] => yyyyyyyy
                    [id] => 12345666666
                    [data] => ABCDE
                )

            [1] => Array
                (
                     [name] => ZZZZZZZZZZZ
                    [category] => JJJJJJ
                    [id] => 88888888888888
                    [data] => ABCDEHIJK
                )

        )

)

I need to get the data from the first array only. I don't want to use a loop. I have tried this:

$name = $data['data'][0]['name'];

but that doesn't get the name. Does anyone know how I can get the specific name only from the first array?

EDIT** my code:

$movie_details_tmdb = $tmdb->searchMovie($search);
$movie_details_tmdb_results = json_decode(json_encode($movie_details_tmdb), true);
$id = $movie_details_tmdb_results['results'][0]['id'];

it's in the same format as the code above.

4

1 回答 1

0

也许你对json有问题?

(PHP 5 >= 5.2.0,PECL json >= 1.2.0)

将对象转换为数组的更好方法:

$arr = (array) $obj;
于 2013-03-18T22:47:07.930 回答