6.2.6 PHP多维数组

6.2.6 PHP多维数组

二维数组的声明与应用

v二维数组的声明
v多维数组的声明方式及规则,与一维数组相同,例如:下面二维数组的声明片段:

6.2.6 PHP多维数组_第1张图片
图片117.png

v这时数组中的资料内容如下:
tp://upload-images.jianshu.io/upload_images/2665727-033075116bae6aca.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
v如果以 array 语法声明,则如下程序片段:

19.png
v\:* {behavior:url(#default#VML);}o\:* {behavior:url(#default#VML);}p\:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);}v\:textbox {display:none;}
幻灯片 4
.O  {font-size:149%;}

 **array**(1,'高某','A公司','北京市','(010)98765432', '[email protected]'),
           "上海联系人" => **array**(2,'洛某','B公司','上海市','(021)12345678', '[email protected]'),
           "天津联系人" => **array**(3,'峰某','C公司','天津市','(022)24680246', '[email protected]'),
           "重庆联系人" => **array**(4,'书某','D公司','重庆市','(023)13579135', '[email protected]')
       );
**    ****    echo** "第一个联系人的公司:".$contact1[0][2]."
"; //输出A公司 **echo**"上海联系人的EMAIL:".$contact2["上海联系人"][5]."
"; //输出[email protected]
 **array**(1,'高某','A公司','北京市','(010)98765432', '[email protected]'),
           "上海联系人" => **array**(2,'洛某','B公司','上海市','(021)12345678', '[email protected]'),
           "天津联系人" => **array**(3,'峰某','C公司','天津市','(022)24680246', '[email protected]'),
           "重庆联系人" => **array**(4,'书某','D公司','重庆市','(023)13579135', '[email protected]')
       );
**    ****    echo** "第一个联系人的公司:".$contact1[0][2]."
"; //输出A公司 **echo**"上海联系人的EMAIL:".$contact2["上海联系人"][5]."
"; //输出[email protected]
 **array**(
            **array**(1, "高某", "市场部经理", 5000.00),
            **array**(2, "洛某", "职员", 3000.00),
            **array**(3, "峰某", "职员", 2400.00),
        ),
        "产品部" => **array**(
            **array**(1, "李某", "产品部经理", 6000.00),
            **array**(2, "周某", "职员", 4000.00),
            **array**(3, "吴某", "职员", 3200.00)
        ),
        "财务部" => **array**(
            **array**(1, "郑某", "财务部经理", 4500.00),
            **array**(2, "王某", "职员", 2000.00),
            **array**(3, "冯某", "职员", 1500.00)
        )
    );
    print_r($wage["市场部"]);          //访问数组$wage中的第一个元素
    print_r($wage["市场部"][1]);       //访问数组$wage["市场部"]中的第二个元素
    print_r($wage["市场部"][1][3]);    //访问数组$wage["市场部"][1]中的第四个元素,输出3000

1.php

 [
            ["name"=>"zs", "age"=>20, "sex"=>"男", "email"=>"[email protected]"], 
            ["name"=>"ls", "age"=>21, "sex"=>"女", "email"=>"[email protected]"], 
            ["name"=>"ww", "age"=>22, "sex"=>"男", "email"=>"[email protected]"]
    ],

     [
            ["name"=>"zs", "age"=>20, "sex"=>"男", "email"=>"[email protected]"], 
            ["name"=>"ls", "age"=>99, "sex"=>"女", "email"=>"[email protected]"], 
            ["name"=>"ww", "age"=>22, "sex"=>"男", "email"=>"[email protected]"]
    ],

     [
            ["name"=>"zs", "age"=>20, "sex"=>"男", "email"=>"[email protected]"], 
            ["name"=>"ls", "age"=>21, "sex"=>"女", "email"=>"[email protected]"], 
            ["name"=>"ww", "age"=>22, "sex"=>"男", "email"=>"[email protected]"]
    ]
];
    echo $class[0][1]['age'];
    echo '
';
    print_r($class);
    echo '
';

test.php

';
    print_r($group);
    echo '
';

你可能感兴趣的:(6.2.6 PHP多维数组)