A two-dimensional array is also called a matrix. in essence, an array is used as an array of array elements. If an array element is a one-dimensional array, this array is called a two-dimensional array.
What is a two-dimensional php array?
A two-dimensional array is also called a matrix. in essence, an array is used as an array of array elements. If an array element is a one-dimensional array, this array is called a two-dimensional array.
PHP two-dimensional array example
In our previous article "PHP array type-multi-dimensional array", we explained two-dimensional arrays. text descriptions may make everyone more confused and intuitive without code examples, the following is an example to show you at a glance!
PHP two-dimensional array code example:
Array ("PHP", "Chinese", "net"), "Sporting Goods" => array ("M" => "football ", "N" => "Basketball"), "fruit" => array ("Orange", 8 => "grape", "Apple ")); // declare the array print_r ($ ASD); // Print the output array?>
Output result:
Array ([website] => Array ([0] => PHP [1] => Chinese [2] => Network) [Sporting Goods] => Array ([M] => Football [N] => Basketball) [fruit] => Array ([0] => Orange [8] => Grape [9] => Apple ))
It is described as follows:
Many people see why the following table for "Apple" is "9?
We have mentioned in previous articles that the array subscript starts from 0 by default and increases by 1 in turn. of course, you can also specify a number to start, because we previously defined "grape" as 8, the subscript of "apple" is 9. What do you understand now?
The above example implements the declaration of a two-dimensional array. in this way, we can declare an array with a higher dimension. isn't it easy, refer to our previous article "PHP array type-multi-dimensional array"!
[Recommended tutorials]
1. related topic recommendations: php Array (Array)
What is the above two-dimensional php array? For more details about php two-dimensional array instances, see other related articles in the first PHP community!