如何从JSON数组响应中检索值

时间:2022-09-13 13:21:00

I want to fetch ahmedabad,surat from location key. I am giving an output

我想从位置键获取ahmedab​​ad,surat。我正在给出一个输出

$jsonResponse = Zend_JSON::decode(substr($response['body'], 9));

print_r($jsonResponse['result']);

//output :Array ( [0] => Array ( [location] => ahmedabad [id] => 18x49 ) [1] => Array ( [location] => Surat [id] => 18x42 ) )

I went to through the solutions on many websites but cudnot get how to accomplish this. Please I appericate your help. I hope i have given essential details.

我在许多网站上浏览了解决方案,但没有得到如何实现这一点。请为我提供帮助。我希望我已经提供了必要的细节。

2 个解决方案

#1


3  

Loop in elements:

循环元素:

foreach($jsonResponse['result'] as $val){
    echo $val['location'];
}

#2


1  

$jsonResponse['result'][0]['location'] // 'ahmedabad'
$jsonResponse['result'][1]['location'] // 'Surat'

#1


3  

Loop in elements:

循环元素:

foreach($jsonResponse['result'] as $val){
    echo $val['location'];
}

#2


1  

$jsonResponse['result'][0]['location'] // 'ahmedabad'
$jsonResponse['result'][1]['location'] // 'Surat'