Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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 RedditAPI-使用foreach()从Json中提取信息_Php_Foreach_Json_Reddit - Fatal编程技术网

Php RedditAPI-使用foreach()从Json中提取信息

Php RedditAPI-使用foreach()从Json中提取信息,php,foreach,json,reddit,Php,Foreach,Json,Reddit,我试图使用PHP的foreach()循环从RedditJSONAPI中提取标题和url 这是我到目前为止的代码 $string_reddit = file_get_contents("http://reddit.com/hot.json"); $json = json_decode($string_reddit, true); 我添加了echo($title);回声“”;它似乎只输出.json中的第一个和最后一个条目;回声“”;它似乎只输出.json中的第一个和最后一个条目。 $string_

我试图使用PHP的foreach()循环从RedditJSONAPI中提取标题和url

这是我到目前为止的代码

$string_reddit = file_get_contents("http://reddit.com/hot.json");
$json = json_decode($string_reddit, true);
我添加了echo($title);回声“
”;它似乎只输出.json中的第一个和最后一个条目;回声“
”;它似乎只输出.json中的第一个和最后一个条目。
$string_reddit = file_get_contents("http://reddit.com/hot.json");
$json = json_decode($string_reddit, true);  

$children = $json['data']['children'];
foreach ($children as $child){
    $title = $child['data']['title'];
    $url = $child['data']['url'];
}