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.