PHP array access related questions

Source: Internet
Author: User
First of all, it is said that the PHP array is copied from the PERL array, but its usage is simplified. To access an array, the members are: $ array name [key name] or $ array name {key name}. in PERL, [] indexes refer to arrays, {} is dedicated to hash arrays. But I guess there are some problems with accessing the P PHP array.

First, it is said that the PHP array is copied from the PERL array, but its use is simplified.

To access the members in an array, the following are required:

$ Array name [key name]

Or

$ Array name {key name}

In PERL, [] indexes refer to arrays, and {} is dedicated to hash arrays.

However, the {} index method is not described in the official PHP documentation. It only exists in the user comment. Naturally, I think these users must have read the PHP source code. It may be inadvertently tested.

But in any case, if you don't look at the source code, you won't be able to tell the real difference between the two.

?

In addition, you can use arrays to access a single character in a string. However, if the variable is empty. Write a string into the array.

?

For strings, I personally prefer {} type index access. The fundamental purpose of this operation is to distinguish it from an array. Indicates that this variable is a string.

?

For the difference between [] and {}, you need to check the source code later. Make only some records.

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.