What is a PHP two-dimensional array?
A two-dimensional array, also known as a matrix, is essentially an array of array elements, an array of elements if it is a one-dimensional array, then we call this array a two-dimensional array.
PHP Two-dimensional array instance detailed
One of our previous article, "type of PHP array-multidimensional array," there are two-dimensional array, the text description may make everyone more confused, no code example to the intuitive, below we specific examples to let everyone at a glance!
PHP Two-dimensional array code example:
<?phpheader ("content-type:text/html; Charset=utf-8 "); $atr = Array (" Web "=>array (" PHP "," Chinese "," net "), " Sporting Goods "=>array (" M "=" Football "," N "=" basketball " ), "Fruit" =>array ("orange",8=> "Grape", "apple"); Declares an array of print_r ($ATR); Print output Array?>
The output is:
Array ([site] = = Array ([0] = php[1] = Chinese [2] = net) [Sporting goods] = = Array ([M] = = Soccer [N] = basketball) [Fruit] = Ar Ray ([0] = orange [8] = grape [9] = apple))
Here is a description:
Many people see why the "Apple" table above is "9"?
This question our previous article has said that the array subscript default is starting from 0, and then add 1, of course, you can also specify starting from a number, because we have defined the "grape" is 8, so the next "apple" subscript natural is 9. Do the little friends understand now?
The above example implements a two-dimensional array declaration, according to this idea, can declare the higher dimension of the array, is not very simple, if the two-dimensional array is still some unclear white, you can refer to our previous article "PHP array type-multidimensional array"!
"Related tutorials Recommended"
1. Related topics: "PHP array"