PHP multidimens...LOGIN

PHP multidimensional array

PHP Multidimensional Array


##Arrays with more than one dimension can be called multidimensional arrays

We need to understand that an array is not necessarily a next-dimensional array A simple list of indexes and values. In fact, each element in the array can also be another array

So if the array element in a one-dimensional array is an array, then it becomes a two-dimensional 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 two- or three-dimensional arrays:

Example

<?php
 // 二维数组:
 $cars = array
 (
     array("Volvo",100,96),
     array("BMW",60,59),
     array("Toyota",110,100)
 );
 ?>


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>"); 
 ?>



Example 2

Let us try to display a value in the above array:

echo $sites['php'][0] . 'The address is:' . $sites['php'][1];



For other related array knowledge, please refer to the tutorial PHP Array chapter content.


Next Section

<?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>"); ?>
submitReset Code
ChapterCourseware