开发者

Parse Error in php [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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'];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜