Analysis error in php

Parse Error is described below

echo $xmlArray[OTA_HotelAvailRS][Properties][Property][0_attr][HotelCityCode]; 

error: syntax error, unexpected T_STRING, pending ']'

how to solve it?

+4
source share
3 answers

PHP assumes that unquoted literals are constants, and constant names cannot begin with numbers. This causes 0_attr parsed for the number 0, followed by the constant _attr - which makes no sense.

ALWAYS specify array indices.

  echo $xmlArray['OTA_HotelAvailRS']['Properties']['Property']['0_attr']['HotelCityCode']; 
+10
source

missing quotes:

 echo $xmlArray['OTA_HotelAvailRS']['Properties']['Property']['0_attr']['HotelCityCode']; 
+3
source

If all these words are not defined as constants, you are doing something wrong. I assume PHP gives an error on 0_attr, but I'm not quite sure. In any case, indexes are strings, so you need to wrap them in quotation marks;

 <?php echo $xmlArray['OTA_HotelAvailRS']['Properties']['Property']['0_attr']['HotelCityCode']; 
+3
source

All Articles