Parse Error in php [closed]
Bellow statement showing Parse Error
echo $xmlArray[OTA_HotelAvailRS][Properties][Property][0_attr][HotelCity开发者_运维知识库Code];
error: syntax error, unexpected T_STRING, expecting ']'
how to solve this?
PHP assumes unquoted literals to be constants and constant names can't start with numbers. This results as 0_attr
being parsed to a number 0 followed by a constant _attr
- which does not amke any sense.
ALWAYS quote array indices.
echo $xmlArray['OTA_HotelAvailRS']['Properties']['Property']['0_attr']['HotelCityCode'];
quotes missing :
echo $xmlArray['OTA_HotelAvailRS']['Properties']['Property']['0_attr']['HotelCityCode'];
Unless all of those words are defined as constants, you're doing something wrong. I imagine PHP is giving the error on 0_attr, but I'm not exactly sure. Anyway, the indexes are strings, so you have to wrap them in quotes;
<?php
echo $xmlArray['OTA_HotelAvailRS']['Properties']['Property']['0_attr']['HotelCityCode'];
精彩评论