Blogger Information
Blog 26
fans 1
comment 0
visits 22289
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP第三课:多维数组和多维数组的循环遍历
孤忆寻昔R
Original
736 people have browsed it

作业

关键字的使用 

=>   as   array();

实例

<?php

//创建数组
$arr = array(
    10,
    20,
    '朱老师',
    12,
    null,
);

//print_r($arr);

//索引数组,
$arr1 = array(
    '长江',
    '黄河',
    012,
);
//var_dump($arr1);

//关联数组
$arr2 = array(
    'age'=>'20',
    'name'=>'六脉无疆',
    'sex'=>'男'
);
//var_dump($arr2);

//访问age、name键的值
//echo $arr2['age'];
//echo $arr2['name'];

//二维数组
$arr3 = array(
    array(
        'age'=> 20,
        'name'=> '双方各',
        'sex'=> '女'
    ),

    array(
        'age'=> 20,
        'name'=> '立体声',
        'sex'=> '女'
    ),
);
//var_dump($arr3);
//
//print_r($arr3[1]['name']);

//三维数组

$arr4 = [
    [
        'age'=> 20,
        'name'=> '双方各',
        'sex'=> '女',
        'jineng'=>[
            'php',
            'html',
            'css'
        ],
    ],
    [
        'age'=> 20,
        'name'=> '大师傅',
        'sex'=> '男',
        'jineng'=>[
            'java',
            'html'
        ],
    ],
    [
        'age'=> 20,
        'name'=> '双方各',
        'sex'=> '女',
        'jineng'=>[
            'css',
            'html',
            'js'
        ],
    ],
];
//var_dump($arr4);
//print_r($arr4[2]['jineng'][null]);

//二维数组的遍历
//foreach($arr3 as $value){
//    foreach ($value as $val){
//       echo  $val;
//    }
//}

//三维数组的遍历
foreach($arr4 as $val1){
    echo '年龄'.$val1['age'].'------';
    echo 'name'.$val1['name'].'------';
        foreach($val1['jineng'] as $v){
               echo $v.'</br>'.'----';
        }


}
QQ图片20191114004037.jpg

总结
1、循环一次加 foreach($arr as $value){
    echo $value;
}  
第二次 加foreac($value as $vv){
    echo $vv;
}
第三次循环
foreach($val1['jineng'] as $v){
echo $v.'</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