我的站点中有一个页面,我必须在其中解析 xml 并将结果插入数组。但是当我尝试插入数组房间时,我遇到了这个错误:
Indirect modification of overloaded element of SimpleXMLElement has no effect
错误在这一行:
$hotel_array[$id]['rooms'][$i] = $room_array;
这是我的代码:
$hotel_array = array();
//$xml->data is a valid xml parsed with simpleXML
foreach ($xml->DATA as $entry){
foreach ($entry->HOTEL_DATA as $entry2){
$id = (string)$entry2->attributes()->HOTEL_CODE;
if($entry2->attributes()->HOTEL_CODE=='YYG'){
$exist = 0;
if (array_key_exists('YYG', $hotel_array))
$exist = 1;
$hotel_array[$id] = $entry2->attributes()->HOTEL_CODE;
$i=0;
foreach($entry2->ROOM_DATA as $room){
$room_array = array();
$room_array['id'] = $room->attributes()->CCHARGES_CODE;
$room_array['code'] = $room->attributes()->ROOM_CODE;
$room_array['name'] = utf8_decode($room->ROOM_NAME);
>attributes()->NO_OF_EXTRA_BEDS;
$hotel_array[$id]['rooms'][$i] = $room_array;
$i++;
}
}
}