Blogger Information
Blog 16
fans 0
comment 0
visits 12372
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php基础数组-11月13日作业
wenbin0209
Original
605 people have browsed it

实例

<?php

// 数组创建

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

// 索引数组

$arr = [
  '孙尚香',
  '猴子',
  '安其拉'
];

// 关联数组

$arr = [
    'sunshangxiang' => '孙尚香',
    'houzi' => '猴子',
    'anqila' => '安其拉'
];

// ****多维数组*****

// 二维数组
$arr1 = [
    [
        'name' => '孙尚香',
        'zhiye' => '射手'
    ],
    [
        'name' => '猴子',
        'zhiye' => '打野'
    ],
    [
        'name' => '安其拉',
        'zhiye' => '法师'
    ]
];

// 二维数组循环
foreach($arr1 as $k => $v){
    echo $v['name'] .'=='. $v['zhiye'];
    echo '<hr>';
}

// 三维数组

$arr2 = [
    [
        'name' => '孙尚香',
        'zhiye' => '射手',
        'jineng' => [
            '活力迸发',
            '翻滚突袭',
            '红莲爆弹',
            '究极弩***'
        ]
    ],
    [
        'name' => '猴子',
        'zhiye' => '打野',
        'jineng' => [
            '活力迸发',
            '翻滚突袭',
            '红莲爆弹',
            '究极弩***'
        ]
    ],
    [
        'name' => '安其拉',
        'zhiye' => '法师',
        'jineng' => [
            '活力迸发',
            '翻滚突袭',
            '红莲爆弹',
            '究极弩***'
        ]
    ]
];



// 三维数组循环
foreach($arr2 as $v){
    echo '姓名:'. $v['name'];
    echo '<br>';
    echo '职业:'. $v['zhiye'];
    echo '<br>';
    echo '技能:';
    foreach($v['jineng'] as $k => $vv){
        echo $vv.'-';
    }
    echo '<hr>' ;
}

运行实例 »

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

 

image.png

image.png


总结:学习了数组的创建,二维数组,三维数组,foreach循环


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!