Blogger Information
Blog 9
fans 0
comment 0
visits 5673
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组与foreach循环----第九期线上培训班
平胸啊春
Original
569 people have browsed it

创建数组

<?php
    //创建数组
    //索引数组
    $arr = array(
        '王思聪',
        '王健林',
        '马云',
        '马化腾'
    );
    //关联数组
    $arr1 = array(
       'xiongmao' => '王思聪',
        'wanda' => '王健林',
        'taobao' => '马云',
        'tengxun' => '马化腾'
    );
    //访问数组数据
    print_r($arr1);
    echo '<hr>';
    //创建二维数组
    $arr2 = array(
        'wsc',
        'wjl',
        'my',
        'mht' => array(
            'qq',
            'qqyx',
            'qqyy'
        )
    );
    print_r($arr2);
    echo '<hr>';
    //创建三维数组
    $arr3 = array(
        'wsc',
        'wjl',
        'my',
        'mht' => array(
            'qq',
            'qqyx' => array(
                'cjzz',
                'wzry',
                'yxlm'
            ),
            'qqyy'
        )
    );
    print_r($arr3);
    echo '<hr>';
    //二维数组循环遍历
    foreach($arr2 as  $value1){
        if(is_array($value1)) {
            foreach ($value1 as $value2) {
                echo $value2 . '<br>';
            }
        }else{
            echo $value1 . '<br>';
        }
    };
    echo '<hr>';
    //三维数组循环遍历
    foreach($arr3 as  $value1){
        if(is_array($value1)) {
            foreach ($value1 as $value2) {
                if(is_array($value2)) {
                    foreach ($value2 as $value3) {
                        echo $value3 . '<br>';
                    }
                }else{
                    echo $value2 . '<br>';
                }
            }
        }else{
            echo $value1 . '<br>';
        }
    };


效果预览图

QQ图片20191114193237.png

手抄代码

QQ图片20191114193450.jpg

QQ图片20191114193509.jpg

QQ图片20191114193538.jpg


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