Blogger Information
Blog 77
fans 0
comment 0
visits 55257
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php数组作业_0916
Jet的博客
Original
493 people have browsed it

实例

<?php
    //创建索引数组两种方式
    echo '索引数组';
    $arr = array('北京','西安','湖北');
    $arrs = ['北京','西安','湖北'];
    var_dump($arr);
    echo '<br />';
    var_dump($arrs);
    echo '<hr>';
    //关联数组
    $name = array(
        'zhangsan'  => '张三',
        'lisi'      => '李四',
        'wangwu'    => '王五'
    );
    //关联数组,更方便于读取信息,因为下标名称更具有代表性

    echo "关联数组" . '<br />';
    //二维数组
    $intro = array(
        array(
            'name'  => '张三',
            'age'   => 18
        ),
        array(
            'name'  => '李四',
            'age'   => 19
        )
    );
    var_dump($intro);
    echo '<br />';
    foreach($intro as $k=>$v){
        foreach($v as $key=>$value){
            echo $key . ':' . $value;
            echo '<br />';
        }
    };

    echo '<hr>';
    echo "三维数组" . '<br />';
    //三维数组
    $intro1 = array(
        array(
            'name'  => '张三',
            'age'   => 18,
            'aihao' => [
                '篮球',
                '足球',
                '羽毛球'
            ]
        ),
        array(
            'name'  => '李四',
            'age'   => 19,
            'aihao' => [
                '篮球',
                '足球',
                '羽毛球'
            ]
        ),
        array(
            'name'  => '王五',
            'age'   => 20,
            'aihao' => [
                '篮球',
                '足球',
                '羽毛球'
            ]
        ),
    );
    //循环输出
    foreach($intro1 as $k=>$v){
        foreach($v as $key=>$value){
            //is_array检测$value变量是否一个数组
            if(is_array($value)){
                //如果是就遍历这个数组
                foreach($value as $value1){
                    //然后输出
                    echo $value1;
                    echo '<br />';
                }
            }else{
                //如果不是就按之前的遍历结果
                echo $key . ':' . $value;
                echo '<br />';
            }
        }
    }
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


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