Ask a question about the PHP array

Source: Internet
Author: User
Ask an array of PHP questions
Define an array in PHP
$sz = Array ();

If you add a specific name element to the array, I write it this way.
$sz [A] = "123456";

And then use the Echo $sz [' a '] to output nothing what is this for? Is there any other way, master help?

------Solution--------------------
Output: Notice:use of undefined constant a-assumed ' a ' in D:\www\test.php on line 3
123456
So the assignment will not be able to ah $sz [' a '] = "123456";

------Solution--------------------
1.
$sz =array (' a ' = ' 123456 ');

2.
$sz =array ();
$sz [' A ']= ' 123456 ';


------Solution--------------------
In general, we set the error checking level of PHP to E_all ^ E_notice so that we can give full play to the flexibility of PHP for variable handling, in this case
$sz = Array ();
$sz [A] = "123456";
echo $sz [' a ']; 123456

Of course, as a traditional programmer, you can set the error checking level to E_all
So
$sz = Array ();
$sz [A] = "123456"; A Notice level error will appear here. If the error display function is not turned on, the program will be terminated.
echo $sz [' a ']; 123456

But you should notice that the error description is
Use of undefined constant a-assumed ' a '
Using constants that are not defined

He pointed out the fact that:
Define (' A ', 1);
$sz = Array ();
$sz [A] = "123456";
echo $sz [1]; 123456
  • Related Article

    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.