Blogger Information
Blog 10
fans 0
comment 0
visits 7511
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
几种数组的使用-2019年9月19日18:00
i开哥的博客
Original
702 people have browsed it

实例

<?php
//     $name = '李大猛';
//     $age = 18;
//     $gender = '男';
//
//     $name = '张大胆';
//     $age = 20;
//     $gender='男';

 //     创建数组
//      $arr = array();
//
//      var_dump($arr);
//
//      $arr = [];
//      var_dump($arr);

//      创建索引数组  ,存储多个数据,两个数据之间用逗号 , 隔开
//索引数组,从0 开始
//      $arr = [
//          '李大猛',
//          '张大胆',
//          '李小妹'
//      ];
//      var_dump($arr);
//      print_r($arr);

//创建关联数组
//       $arr = [
//           'zhangsan' => '张三',
//           'lisi' => '李四',
//           'wangwu' => '王五'
//       ];
//       print_r($arr);
//       echo $arr['lisi'];

//二维数组,三维数组,数组中套着数组
//       $arr = [
//        'zhangsan' =>  [
//            'name' => '张三',
//           'age' => 18,
//            'jineng' => ['开车',
//                '电脑'
//                ]
//               ],
//           'lisi' => ['name' => '李四',
//               'age' => 19,
//           ],
//           'wangwu' => ['name' => '王五',
//               'age' => 20,
//           ]
//       ];
//       print_r($arr);
//       echo $arr['zhangsan']['jineng'][0];
//  数组循环
//       $arr = [
//           'zhangsan' => '张三',
//           'lisi' => '李四',
//           'wangwu' => '王五'
//
//
//       ];
//       foreach ($arr as $a) {
//           print_r($a);
//           echo $a;
//
//       }
//       echo $a;

//二维数组循环
        $arr = [
            [
                'zhangsan' => '张三',
                'age' => 18
            ],
            [
                'lisi' => '李四',
                'age' => 20
            ],
            [
                'wangwu' => '王五',
                'age' => 22,
                'son' => [
                    '王大',
                    '王二'
                ]
            ]
        ];
        foreach ($arr as $k => $v) {
            foreach ($v as $key => $value) {
                echo $value;
            }
//            echo $value;
        }

?>

运行实例 »

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

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