Latest web development tutorials

PHP multidimensional array

An array of value can be another array, another array value can also be an array. In this manner, we can create a two-dimensional or three-dimensional array:

Examples

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

Running instance »

PHP - Multidimensional Arrays

Multidimensional array containing one or more arrays of arrays.

In a multidimensional array, main array, each element can also be an array of sub-arrays of each element can also be an array.

Examples

In this example, we create an automatically assigned ID keys multidimensional array:

Examples

<? php
$ sites = array
(
"w3big" => array
(
"Tutorial"
"http://www.w3big.com"
),
"google" => array
(
"Google Search"
"http://www.google.com"
),
"taobao" => array
(
"Taobao"
"http://www.taobao.com"
)
);
print ( "<pre>") ; // output array format
print_r ($ sites);
print ( "</ pre>" );
?>

The above array output as follows:

Example 2

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

echo $sites['w3big'][0] . '地址为:' . $sites['w3big'][1];

The code above will output: