需要关于PHP json_decode()的帮助
需要关于PHP中的需要关于PHP json_decode()的帮助,php,Php,需要关于PHP中的json\u decode()的帮助和建议。我正在处理一个API调用的CURL操作,返回的结果是JSON。访问字段pgid需要什么语法 卷曲操作 $output = curl_exec($ch); $rslt = json_decode($output, true); var_dump($rslt); 变量转储()输出 array (size=1) 'protection-groups' => array (size=3) 0 => array (size
json\u decode()
的帮助和建议。我正在处理一个API调用的CURL操作,返回的结果是JSON。访问字段pgid
需要什么语法
卷曲操作
$output = curl_exec($ch);
$rslt = json_decode($output, true);
var_dump($rslt);
变量转储()输出
array (size=1)
'protection-groups' => array (size=3)
0 => array (size=2)
'ppsDropped' => float 0
'pgid' => int 13
1 => array (size=2)
'ppsDropped' => float 7.9957930115316
'pgid' => int 18
2 => array (size=2)
'ppsDropped' => float 5302.7606884163
'pgid' => int 19
尝试下面的代码,该代码将循环并获取所有
pgid
foreach($rslt['protection-groups'] as $group)
{
echo $group['pgid'];
}
试着这样做:
$output = curl_exec($ch);
$rslt = json_decode($output, true);
$idsArray = array();
foreach($rslt['protection-groups'] as $key => $value){
$pgId = $value['pgid'];
echo $pgId;
//Or in case you need all the PGID's in array then :
array_push($idsArray,$value['pgid']);
}
print_r($idsArray);
exit();
你试过的代码解决了我的问题!!谢谢大家的建议。很高兴能帮助你!请接受我的回答。