PHP multidimensional array
The values in one array can be another array, and the values in another array can also be an array. In this way, we can create a two-dimensional or three-dimensional array:
Instance
<?php // 二维数组: $cars = array ( array("Volvo",100,96), array("BMW",60,59), array("Toyota",110,100) ); print_r($cars); ?>
Run Example»
Click "Run Example" button to view online examples
PHP - Multidimensional Array
A multidimensional array is an array containing one or more 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 multidimensional array with automatically assigned ID keys:
Example
<?php $sites = array ( "php"=>array ( "php中文网", "//m.sbmmt.com" ), "google"=>array ( "Google 搜索", "http://www.google.com" ), "taobao"=>array ( "淘宝", "http://www.taobao.com" ) ); print("<pre>"); // 格式化输出数组 print_r($sites); print("</pre>"); ?>
Run Instance»
Click the "Run Instance" button to view the online instance
The above array will be output as follows:
Example 2
Let us try to display a certain value in the above array:
echo $sites['php'][0] . '地址为:' . $sites['php'][1];The above code will output: