Blogger Information
Blog 13
fans 0
comment 0
visits 7965
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php第三节课 创建数组 线上第九期作业
大葫芦
Original
689 people have browsed it

实例

<?php
// 新建数组 第一种方式 创建索引数组
$arr1 = array(
    '欧阳克',
    '18岁',
    'php讲师',
);
//输出方式 一维数组最好不用foreach 循环
echo $arr1[0];

//创建数组的第二种方式 创建索引数组
$arr2 = [
    '西门大官人',
    '28岁',
    'html讲师',
];
//输出方式一样

echo $arr2[1];

//创建关联数组,关联数组的key 键名 要用英文

$arr3 = array(
    'name'=>'朱老师',
    'age'=>'28岁',
    'job'=>'js讲师',
);

//输出方式
echo $arr3['name'];

//创建二维数组

$arr4 =[
    [
        'name'=>'西门大官人',
        'age'=>'48岁',
        'job'=>'css讲师',
    ],
    [
        'name'=>'朱老师',
        'age'=>'58岁',
        'job'=>'js讲师',
    ],
    [
        'name'=>'欧阳克',
        'age'=>'18岁',
        'job'=>'php讲师',
    ],
];
foreach ($arr4 as $value){

    //打印
    print_r($value);
};

//foreach 输出二维数组
foreach($arr4 as $key => $value){
    echo '姓名:'.$value['name'];
    echo '年龄:'.$value['age'];
    echo '年龄:'.$value['job'];
    echo '<hr>';
};

//创建三维数组 

$arr5 =[
    [
        'name'=>'西门大官人',
        'age'=>'48岁',
        'job'=>'css讲师',
        'jineng'=>[
            'php实战',
            'js实战',
            'css实战',

        ]
    ],
    [
        'name'=>'朱老师',
        'age'=>'58岁',
        'job'=>'js讲师',
        'jineng'=>[
            'html讲师',
            'js讲师',
            'css讲师',
        ]
    ],
    [
        'name'=>'欧阳克',
        'age'=>'18岁',
        'job'=>'php讲师',
        'jineng'=>[
            'php讲师',
            'js讲师',
            'css讲师',
        ]
    ],
];

//三维数组 循环输出

foreach($arr5 as $value){
    echo '姓名:'.$value['name'].'<br>';
    echo '年龄:'.$value['age'].'<br>';
    echo '职业:'.$value['job'].'<br>';
    echo '牛逼技能:';
    foreach( $value['jineng'] as $v2){
        echo $v2.'-';
    };
    //输出一组后来个横线
    echo '<hr>';
};

运行实例 »

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


手写作业

pppppp.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
Author's latest blog post