[Solved] Is Putting Quotes on PHP Named Indexes Unnecessary?


Your first example should throw a NOTICE. If you do not use quotes then PHP will look for a constant with that name.

php > $myArr = [abc => 'hello'];
PHP Notice:  Use of undefined constant abc - assumed 'abc' in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0

Notice: Use of undefined constant abc - assumed 'abc' in php shell code on line 1

Call Stack:
    9.7779     350840   1. {main}() php shell code:0

I ran this example in PHP 7.1.8, however in PHP 7.2 this has been deprecated.

2

solved Is Putting Quotes on PHP Named Indexes Unnecessary?