Blogger Information
Blog 34
fans 0
comment 0
visits 22406
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP数组—php九期
曾龙宇
Original
618 people have browsed it

一、创建数组

$arr = array();
$arr1 = [];

二、创建索引数组

$arr = [
    1,2,3,4,5,6,7
];
print_r($arr);

三、创建关联数组

$arr1 = [
    'name'=>'张三',
    'age'=>'25',
    'sex'=>'男',
    'city'=>'广州'
];
print_r($arr1);

四、访问数组数据

echo $arr[0];
echo $arr[1];
echo $arr[2];
echo '<br>';
echo $arr1['name'];
echo $arr1['sex'];

五、创建二维数组并循环

$arr = array(
    array(
        'name'=>'张三',
        'sex'=>'男'
    ),
    array(
        'name'=>'李四',
        'sex'=>'男'
    ),
    array(
        'name'=>'李莉',
        'sex'=>'女'
    )
);
foreach ($arr as $v){
    echo $v['name'];
    echo '<br>';
}
echo '<hr>';
foreach ($arr as $k=>$v){
    foreach ($v as $key=>$value){
        echo $value;
        echo '<br>';
    }
}

六、创建三维数组并循环

$arr = [
    [
        'name'=>'张三',
        'sex'=>'男',
        'body'=>[
            'height'=>'170',
            'weight'=>'60'
        ]
    ],
    [
        'name'=>'李四',
        'sex'=>'男',
        'body'=>[
            'height'=>'120',
            'weight'=>'65'
        ]
    ],
    [
        'name'=>'李莉',
        'sex'=>'女',
        'body'=>[
            'height'=>'158',
            'weight'=>'48'
        ]
    ]
];

foreach ($arr as $v){
    echo '姓名:'.$v['name'].'--';
    echo '性别:'.$v['sex'].'--';
    echo '身体状况:';
    foreach ($v['body'] as $vv){
        echo $vv.'-';
    }
    echo '<br>';
}


Correcting teacher:查无此人查无此人

Correction status:qualified

Teacher's comments:完成的不错。
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post