我在PHP中有一個變量$arr
。它裏面有以下數據。如何通過PHP中的JSON對象循環?
這是我的PHP代碼。
$data = array(
'Request' => 'StockStatus',
'merchant_id' => 'shipm8',
'hash' => '09335f393d4155d9334ed61385712999'
);
$url = 'https://ship2you.com/ship2you/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
$arr = json_decode($result, true);
foreach ($arr as $value) {
echo $value['packagename'];
}
我想通過它循環。我怎樣才能實現它?我嘗試使用foreach,但它給了我錯誤。提前致謝。
顯示您是如何使用foreach的? –
也發佈確切的錯誤消息。 – Dencker
可能的重複[如何通過JSON對象循環](http://stackoverflow.com/questions/16290798/how-do-i-loop-through-json-object) – Xorifelse