Php RedditAPI-使用foreach()从Json中提取信息
我试图使用PHP的foreach()循环从RedditJSONAPI中提取标题和url 这是我到目前为止的代码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_
$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'];
}