Reddit json 和 PHP - 打开 foreach() 并获取值

Reddit json and PHP - opening foreach() and getting values

我正在尝试以我的帐户为例阅读 reddit json。

尝试了上面的解决方案:

$string_reddit = file_get_contents("https://www.reddit.com/user/joshfolgado/about.json");

$json = json_decode($string_reddit, true);  

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

$linkkarma = $child['data']['link_karma'];

}

也尝试过:

foreach ($json->data as $mydata){

$values["Latest_Karma"] = $mydata['link_karma'];

}

也尝试过:

$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: reddiant api script\r\n"
));

$context = stream_context_create($opts);
$url = "http://www.reddit.com/user/joshfolgado/about.json";
$json = file_get_contents($url, false, $context);

$result = json_decode($json, true);

foreach ($result as $child){
    $values['Latest_Karma'] = $child['data']['link_karma'];
}

花了几个小时尝试获取 "data" 数组中任何项目的值,但一直无法获取。

我做错了什么?我错过了什么?

感谢任何帮助。

谢谢

$string_reddit = file_get_contents("http://www.reddit.com/user/joshfolgado/about.json");
$json = json_decode($string_reddit, true);  

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

对 pee2pee 的 post 稍作修改(他为我返回了一个未定义的索引错误)

$string_reddit = file_get_contents("http://www.reddit.com/user/joshfolgado/about.json");
$json = json_decode($string_reddit, true);

$children = $json['data'];
$user = [];

foreach ($children as $key => $value)
{
    $user[$key] = $value;
}

echo $user['name']; //Now you can use the $user array to access all the properties!

这对我有用 ->