Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Error in php [closed]

Tags:

arrays

php

xml

Bellow statement showing Parse Error

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

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

how to solve this?

like image 801
Hearaman Avatar asked Dec 05 '22 21:12

Hearaman


1 Answers

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'];
like image 54
Mchl Avatar answered Dec 10 '22 11:12

Mchl