2012-10-04 43 views
1

我想從位置關鍵字獲取ahmedab​​ad,surat。我給出了一個輸出如何從JSON數組響應中檢索值

$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)) 

我去了很多網站上的解決方案,但不知道如何做到這一點。請給我一些幫助。我希望我已經提供了重要的細節。

+0

瞭解數組:http://www.php.net/manual/en/language.types.array.php –

回答

3

迴路中的元素:

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

感謝@mihailorga,一旦agian你已經做到了..高興:) –

+0

請記住,當有人回答你的問題,並解決你的問題接受最適合你的答案時,同樣的事情適用於你過去的任何問題。 –

+0

這是更好的/更一般的方式,因爲我想你想使用比你在例子中提供的數據更多的數據。 –

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