-1
訪問數組元素我已經使用json_decode獲取從JSON響應的數組:無法與json_decode
$result = (json_decode($trends,true));
這使我以下(I沒有包括所有EstablishmentDetail陣列結果)
Array ([FHRSEstablishment] => Array ([Header] => Array ([#text] => [ExtractDate] => 2012-05-28 [ItemCount] => 5 [ReturnCode] => Success) [EstablishmentCollection] => Array ([EstablishmentDetail] => Array ([0] => Array ([FHRSID] => 248659 [LocalAuthorityBusinessID] => INS/06/06179 [BusinessName] => Ancient Raj [BusinessType] => Restaurant/Cafe/Canteen [BusinessTypeID] => 1 [AddressLine1] => 26 North Lane, Canterbury, [PostCode] => CT2 7EE [RatingValue] => 3 [RatingKey] => fhrs_3_en-GB [RatingDate] => 2010-11-18 [LocalAuthorityCode] => 180 [LocalAuthorityName] => Canterbury City [Scores] => [SchemeType] => FHRS [Geocode] =>)
,我以爲我」能夠使用foreach才能到BUSINESSNAME:
foreach ($result->FHRSEstablishment->EstablishmentCollection->EstablishmentDetail as $detail){
echo $detail['BusinessName'];
}
但我沒有得到任何結果。
'$ result'是一個數組,不是對象,因此使用' - >'不起作用。 –
如果您想要更多答案,請格式化數組輸出。 –
請在使用它們的同時瞭解語言特性:http://php.net/array – hakre