Ask a PHP array question. define an array $ sz = array () in PHP. if you add a specific name element to the array, write $ sz [a] = & quot; 123456 & quot; and then output nothing in echo $ sz ['A']. why? Is there any other way? could you help me? output: N 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 --------------------
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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.