ThinkPHP learning-array learning

Source: Internet
Author: User
: This article mainly introduces ThinkPHP learning-array learning. For more information about PHP tutorials, see. PHP array

Many similar variables need to be created either early or late during PHP development. Without many similar variables, you can store data as elements in an array. All elements in the array have their own IDs (I .e. subscripts), so they can be easily accessed. There are three types of arrays: 1. value array: an array with the digit ID key; 2. join array: each ID key in the array is associated with a value. 3. multi-dimensional array: an array that contains one or more arrays.

Numeric array
Example 1
In this example, the ID key is automatically assigned:

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

You can use these ID keys in the script:

Output of the above code: array1 or array2 orarray3 ···

Join array
Join array. each ID key is associated with a value. It is not the best practice to use a numeric array to store data related to specific named values. By associating arrays, we can use values as keys and assign values to them.
Example 1
In this example, we use an array to allocate age to different arrays:

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

You can also use the ID key in the script:

Output of the above script: array1 is 1 number.

Multi-dimensional array
In a multi-dimensional array, each element in the main array is also an array. Each element in the sub-array can also be an array, and so on.
Example 1
In this example, we create a multidimensional array with an automatically assigned ID key:

If this array is output, it should be similar to the following:


The above introduces ThinkPHP learning-array learning, including the content, hope to be helpful to friends who are interested in PHP tutorials.

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.