Home  >  Article  >  Backend Development  >  How to define a two-dimensional array in php

How to define a two-dimensional array in php

藏色散人
藏色散人Original
2019-10-09 09:22:2416584browse

How to define a two-dimensional array in php

How to define a two-dimensional array in php?

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:

The code example is as follows:

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

Output:

Array
(
    [0] => Array
        (
            [0] => Volvo
            [1] => 100
            [2] => 96
        )

    [1] => Array
        (
            [0] => BMW
            [1] => 60
            [2] => 59
        )

    [2] => Array
        (
            [0] => Toyota
            [1] => 110
            [2] => 100
        )

)

For more PHP knowledge, please visit PHP中文网!

The above is the detailed content of How to define a two-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn