PHP array-php Tutorial

Source: Internet
Author: User
Tags php error
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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.