<?php
//1 创建数组
$name =array(
1,
2,
3,
);
//print_r($name);
//2 关联数组
$name =array(
120 =>'中国',
121 =>'美国',
122 =>'日本',
);
//print_r($name);
//3二维数组
$name =[
[
1,
张三,
student,
],
[
2,
李四,
teacher,
],
[
3,
王五,
ohter,
],
];
//print_r($name);
//print_r($name[2][2]);
//4三维数组
$name =[
[
1,
张三,
student,
[
英语,
数学,
语文,
]
],
[
2,
李四,
teacher,
[
物理,
化学,
生物,
],
],
[
3,
王五,
ohter,
[
政治,
历史,
地理,
],
],
];
//print_r($name);
//print_r($name[2][3][0]);
//5 一维数组遍历
$name =array(
120 =>'中国',
121 =>'美国',
122 =>'日本',
);
foreach($name as $key => $v){
echo $key.'==='.$v;
echo '<hr>';
}
//6 二维数组遍历
$name =[
[
1,
张三,
student,
],
[
2,
李四,
teacher,
],
[
3,
王五,
ohter,
],
];
foreach($name as $v){
foreach($v as $key=> $vv){
echo $key.'==='.$vv;
echo '<hr>';
}
}
foreach($name as $v){
echo $v[1];
echo '<hr>';
}
//7 三维数组遍历
$name =[
[
1,
张三,
student,
[
英语,
数学,
语文,
]
],
[
2,
李四,
teacher,
[
物理,
化学,
生物,
],
],
[
3,
王五,
ohter,
[
政治,
历史,
地理,
],
],
];
foreach($name as $v){
foreach($v[3] as $vv){
echo $vv;
echo '<hr>';
}
}