Thinkphp Learning--Array learning

Source: Internet
Author: User
PHP arrays

In the process of using PHP for development, either early or late, you will need to create many similar variables. Without a lot of similar variables, you can store the data in an array as an element. The elements in the array have their own IDs (that is, subscripts), so they can be easily accessed. There are three types of arrays: 1. Arrays of values: arrays with numeric ID keys, 2. Associative arrays: Each ID key in an array associates a value; 3. Multidimensional arrays: An array that contains one or more arrays.

Array of values
Example 1
In this example, the ID key is automatically assigned:

Example 2
In this example, we manually assign the ID key:

You can use these ID keys in your script:

Output of the above code: ARRAY1 or array2 orarray3

Associative arrays
An associative array in which each ID key is associated with a value. Using numeric arrays is not the best practice when storing data about a specific named value. With associative arrays, we can use values as keys and assign values to them.
Example 1
In this example, we use an array to assign the age to different array:

Example 2
This example is the same as Example 1, but it shows another way to create an array:

Of course, you can also use the ID key in your script:

Output from the above script: Array1 is 1 number.

Multidimensional arrays
In a multidimensional array, each element in the primary array is also an array. Each element in a sub-array can also be an array, and so on.
Example 1
In this example, we created a multidimensional array with an auto-assigned ID key:

If you output this array, it should look something like this:


The above describes the Thinkphp learning-array learning, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.