I asked following question in my training to explain some point.
Consider following
define(‘Message’,'name’);
$arr[1]=’Hello’;
$arr['Message']=’World’;
$arr['name']=”Jhon”;echo $arr[1].$arr[Message];
Answers Received :
Hello World
Hello name
Hello Jhon
One question and multiple answers ! The right answer is “Hello Jhon” . Does it tickle your brain? why ! .
Please notice there is no single quote around string index – “Message” in $arr[Message] . And, “Message” is a defined constant which is initialized to “name” and $arr['name'] is Jhon
.
Above example explains why we should always provide single quotes to string index.