Ask a PHP array question. define an array $ szarray () in PHP. if you add a specific name element to the array, I write $ sz [a] & quot; 123456 & quot; and then output nothing in echo $ sz [a] mode. why? Is there any other way? could you help? solution ------------------ output: Notice: Use ask a PHP array question?
Define an array in PHP
$ Sz = array ();
If you add a specific name element to the array, I write it like this.
$ Sz [a] = "123456 ";
Then output nothing in echo $ sz ['A']. why? Is there any other way?
------ Solution --------------------
Output: Notice: Use of undefined constant a-assumed 'A' in D: \ www \ test. php on line 3
123456
In this case, the value assignment will fail. $ sz ['A'] = "123456 ";
------ Solution --------------------
1.
$ Sz = array ('a' => '123 ');
2.
$ Sz = array ();
$ Sz ['A'] = '123 ';
------ Solution --------------------
Generally, we set the php error check level to E_ALL ^ E_NOTICE so that we can make full use of php's flexibility in variable processing. in this case
$ Sz = array ();
$ Sz [a] = "123456 ";
Echo $ sz ['A']; // 123456
Of course, as a programmer, you can set the error check level to E_ALL.
Therefore
$ Sz = array ();
$ Sz [a] = "123456"; // a Notice-level error occurs here. If the error display function is not enabled, the program will be terminated.
Echo $ sz ['A']; // 123456
But you should note that the error description is
Use of undefined constant a-assumed 'A'
Use undefined constants
He pointed out the fact that:
Define ('A', 1 );
$ Sz = array ();
$ Sz [a] = "123456 ";
Echo $ sz [1]; // 123456