Multidimensional Arrays
PHP Multidimensional Array
The value in one array can be another array, and the value of another array can also be an array. In this way, we can create a two-dimensional or three-dimensional array:
Example
<?php // 二维数组: $cars = array ( array("Volvo",100,96), array("BMW",60,59), array("Toyota",110,100) ); ?>
PHP - Multidimensional Array
A multidimensional array contains a or Array of multiple arrays.
In a multi-dimensional array, each element in the main array can also be an array, and each element in the sub-array can also be an array.
Example
In this example, we create a multi-dimensional array with automatically assigned ID keys:
Example
<?php $sites = array ( "php"=>array ( "php中文网", "http://www.php.cn" ), "google"=>array ( "Google 搜索", "http://www.google.com" ), "taobao"=>array ( "淘宝", "http://www.taobao.com" ) ); print("<pre>"); // 格式化输出数组 print_r($sites); print("</pre>"); ?>
The above array will be output as follows :
’s ’ :' . $sites['php'][1];The above code will output:
Multidimensional array
The multidimensional array refers to is an array containing one or more arrays.
1. One-dimensional array There are no other arrays in the array, only some variables or values. 2. A single-layer array or multiple arrays are inserted into a two-dimensional array array3. A three-dimensional array inserts an array (B) into the array (A), and Another level of array (C) is inserted into the B array, which we call a three-dimensional array4. Anything with more than three dimensions is called a multi-dimensional array. Difficulties in learning multi-dimensional arrays: Pay attention to the format and tidy up the line breaks and indentations of each dimension. It’s not easy to make mistakes. 【Remember】The separator between array elements is a comma. When inserting an array into an array, do not write a semicolon (;) at the end