1. 创建数组
<?php
$arr1 = array(
'欧阳克','18岁','php讲师'
);
$arr2= [
'朱老师','19岁','php讲师'
];
print_r($arr1);
echo "<br>";
print_r($arr2);
?>
运行效果

2. 关联数组、索引数组
<?php
索引数组的键值是数字
$arr1 = array(
000=>'欧阳克',
111=>'18岁',
222=>'php讲师'
);
$arr2= [
000=>'朱老师',
111=>'19岁',
222=>'php讲师'
];
print_r($arr1);
echo "<br>";
print_r($arr2);
echo "<br>";
//关联数组的键值是字符串
$arr3 = array(
'name'=>'欧阳克',
'age'=>'18岁',
'job'=>'php讲师'
);
$arr4= [
'姓名'=>'朱老师',
'年龄'=>'19岁',
'职业'=>'php讲师'
];
print_r($arr3);
echo "<br>";
print_r($arr4);
echo "<br>";
?>
运行效果

3. 访问数组的数据
<?php
//访问数组里的元素
$arr1 = array(
'name'=>'欧阳克',
'age'=>'18岁',
'job'=>'php讲师'
);
$arr2= [
'姓名'=>'朱老师',
'年龄'=>'19岁',
'职业'=>'php讲师'
];
print_r($arr1['name']);
print_r($arr2['年龄']);
?>
运行效果

4. 二维数组、三维数组
<?PHP
$arr3 = [
[
'name'=>'欧阳克',
'age'=>'18岁',
'job'=>'php讲师'
],
[
'name'=>'朱老师',
'age'=>'19岁',
'job'=>'php讲师'
]
];
print_r($arr3[0]);
echo "<br>";
print_r($arr3[1]);
//三维数组
$arr4 = [
[
'name'=>'朱老师',
'age'=>'19岁',
'job'=>'php讲师',
'course'=>['html','css']
]
];
print_r($arr4);
?>
运行效果

5. 二维数组循环,三维数组循环
//二维数组循环
$arr3 = [
[
'name'=>'欧阳克',
'age'=>'18岁',
'job'=>'php讲师'
],
[
'name'=>'朱老师',
'age'=>'19岁',
'job'=>'php讲师'
]
];
foreach ($arr3 as $v){
print_r($v['name']);
echo "<br>";
}
//三维数组循环
$arr4 = [
[
'name'=>'朱老师',
'age'=>'19岁',
'job'=>'php讲师',
'course'=>['html','css']
],
[
'name'=>'欧阳克',
'age'=>'18岁',
'job'=>'php讲师',
'course'=>['php','js']
]
];
foreach($arr4 as $v){
echo '姓名:'.$v['name'].'--';
echo '年龄:'.$v['age'].'--';
echo '职业:'.$v['job'].'--';
echo '技能:';
foreach($v['course'] as $vv){
echo $vv.'-';
}
echo '<hr>';
}
?>
运行效果

手抄部分



