亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP development basic tutorial multi-dimensional array

1. PHP two-dimensional array

In the primary tutorial, the arrays we learn are all one-dimensional arrays

In this chapter we introduce Multi-dimensional arrays, starting with two dimensions

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 g array:

Create a two-dimensional array as follows:

Example: The code is as follows

<?php
// 二維數(shù)組:
$cars = array
(
    array("Volvo",100,96),
    array("BMW",60,59),
    array("Toyota",110,100)
);
?>

II , 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: We created a multi-dimensional array that automatically assigns ID keys. The code is as follows

<?php 
$sites = array 
( 
    "php"=>array 
    ( 
        "php中文網(wǎng)", 
        "http://ipnx.cn" 
    ), 
    "google"=>array 
    ( 
        "baidu 搜索", 
        "http://www.baidu.com" 
    ), 
    "taobao"=>array 
    ( 
        "淘寶", 
        "http://www.taobao.com" 
    ) 
); 
print("<pre>"); // 格式化輸出數(shù)組 
print_r($sites); //將數(shù)組打印出來
print("</pre>"); 
?>

The output result is as shown on the right

Try to output a single element on the page :

The code is as follows

<?php 
$sites = array 
( 
    "php"=>array 
    ( 
        "php中文網(wǎng)", 
        "http://ipnx.cn" 
    ), 
    "baidu"=>array 
    ( 
        "baidu 搜索", 
        "http://www.baidu.com" 
    ), 
    "taobao"=>array 
    ( 
        "淘寶", 
        "http://www.taobao.com" 
    ) 
); 
echo '歡迎訪問'.$sites['php'][0].'我們的網(wǎng)址是'.$sites['php'][1]
?>

The output result is shown on the right
Note: When creating a multi-dimensional array, pay attention to the commas separating the arrays. The outer array ")" is followed by a semicolon.


Continuing Learning
||
<?php // 二維數(shù)組: $cars = array ( array("Volvo",100,96), array("BMW",60,59), array("Toyota",110,100) ); ?>
submitReset Code