Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 循环通过JSON解码的数组_Php_Arrays_Json - Fatal编程技术网

Php 循环通过JSON解码的数组

Php 循环通过JSON解码的数组,php,arrays,json,Php,Arrays,Json,我正在使用randonuser API生成虚拟图像。API返回我使用JSON\u decode解码的JSON,使用print\r,我得到以下数组: Array ( [results] => Array ( [0] => Array ( [user] => Array (

我正在使用randonuser API生成虚拟图像。API返回我使用
JSON\u decode
解码的JSON,使用
print\r
,我得到以下数组:

Array
(
    [results] => Array
        (
            [0] => Array
                (
                    [user] => Array
                        (
                            [gender] => male
                            [name] => Array
                                (
                                    [title] => mr
                                    [first] => dwight
                                    [last] => evans
                                )

                            [location] => Array
                                (
                                    [street] => 6822 hunters creek dr
                                    [city] => fresno
                                    [state] => vermont
                                    [zip] => 63409
                                )

                            [email] => dwight.evans44@example.com
                            [username] => ticklishostrich542
                            [password] => ebony
                            [salt] => 4xuAIjmh
                            [md5] => 648f472ff152a194c410d774ff9a4b9d
                            [sha1] => f23cc7ffd2b8980d10de86bccc85068ecf9b7b45
                            [sha256] => fec06f7df352a06aab9c30af9d7ab9b5b81dc0bd6b7567b59fba1a731dea6bba
                            [registered] => 1129218274
                            [dob] => 409533355
                            [phone] => (797)-563-6160
                            [cell] => (200)-718-4014
                            [SSN] => 213-46-5200
                            [picture] => Array
                                (
                                    [large] => http://api.randomuser.me/portraits/men/98.jpg
                                    [medium] => http://api.randomuser.me/portraits/med/men/98.jpg
                                    [thumbnail] => http://api.randomuser.me/portraits/thumb/men/98.jpg
                                )

                            [version] => 0.4.1
                        )

                    [seed] => cf744a697a08f256
                )

           . .. .....

and so on. 

我只需要父级
图片
下的
大的
键值。如何使用
foreach
语句循环它

使用
json\u decode($var,true)
,那么你将拥有一个数组,循环将更容易。

使用
json\u decode($var,true)
,那么你将拥有一个数组,循环将更容易。

使用
json\u decode($var,true)
,那么你将拥有一个数组,循环将更容易。

使用
json\u decode($var,true)
,那么您将拥有一个数组,循环将更容易。

只需像平常一样访问它:

$data = json_decode('that json string', true);
foreach($data['results'] as $value) {
    echo $value['user']['picture']['large'];
}

只需像平常一样访问它:

$data = json_decode('that json string', true);
foreach($data['results'] as $value) {
    echo $value['user']['picture']['large'];
}

只需像平常一样访问它:

$data = json_decode('that json string', true);
foreach($data['results'] as $value) {
    echo $value['user']['picture']['large'];
}

只需像平常一样访问它:

$data = json_decode('that json string', true);
foreach($data['results'] as $value) {
    echo $value['user']['picture']['large'];
}