Blogger Information
Blog 12
fans 0
comment 0
visits 8513
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php基础之数组的基础
brait
Original
802 people have browsed it

1. 创建数组

  1. <?php
  2. $arr1 = array(
  3. '欧阳克','18岁','php讲师'
  4. );
  5. $arr2= [
  6. '朱老师','19岁','php讲师'
  7. ];
  8. print_r($arr1);
  9. echo "<br>";
  10. print_r($arr2);
  11. ?>

运行效果


2. 关联数组、索引数组

  1. <?php
  2. 索引数组的键值是数字
  3. $arr1 = array(
  4. 000=>'欧阳克',
  5. 111=>'18岁',
  6. 222=>'php讲师'
  7. );
  8. $arr2= [
  9. 000=>'朱老师',
  10. 111=>'19岁',
  11. 222=>'php讲师'
  12. ];
  13. print_r($arr1);
  14. echo "<br>";
  15. print_r($arr2);
  16. echo "<br>";
  17. //关联数组的键值是字符串
  18. $arr3 = array(
  19. 'name'=>'欧阳克',
  20. 'age'=>'18岁',
  21. 'job'=>'php讲师'
  22. );
  23. $arr4= [
  24. '姓名'=>'朱老师',
  25. '年龄'=>'19岁',
  26. '职业'=>'php讲师'
  27. ];
  28. print_r($arr3);
  29. echo "<br>";
  30. print_r($arr4);
  31. echo "<br>";
  32. ?>

运行效果


3. 访问数组的数据

  1. <?php
  2. //访问数组里的元素
  3. $arr1 = array(
  4. 'name'=>'欧阳克',
  5. 'age'=>'18岁',
  6. 'job'=>'php讲师'
  7. );
  8. $arr2= [
  9. '姓名'=>'朱老师',
  10. '年龄'=>'19岁',
  11. '职业'=>'php讲师'
  12. ];
  13. print_r($arr1['name']);
  14. print_r($arr2['年龄']);
  15. ?>

运行效果


4. 二维数组、三维数组

  1. <?PHP
  2. $arr3 = [
  3. [
  4. 'name'=>'欧阳克',
  5. 'age'=>'18岁',
  6. 'job'=>'php讲师'
  7. ],
  8. [
  9. 'name'=>'朱老师',
  10. 'age'=>'19岁',
  11. 'job'=>'php讲师'
  12. ]
  13. ];
  14. print_r($arr3[0]);
  15. echo "<br>";
  16. print_r($arr3[1]);
  17. //三维数组
  18. $arr4 = [
  19. [
  20. 'name'=>'朱老师',
  21. 'age'=>'19岁',
  22. 'job'=>'php讲师',
  23. 'course'=>['html','css']
  24. ]
  25. ];
  26. print_r($arr4);
  27. ?>

运行效果

5. 二维数组循环,三维数组循环

  1. //二维数组循环
  2. $arr3 = [
  3. [
  4. 'name'=>'欧阳克',
  5. 'age'=>'18岁',
  6. 'job'=>'php讲师'
  7. ],
  8. [
  9. 'name'=>'朱老师',
  10. 'age'=>'19岁',
  11. 'job'=>'php讲师'
  12. ]
  13. ];
  14. foreach ($arr3 as $v){
  15. print_r($v['name']);
  16. echo "<br>";
  17. }
  18. //三维数组循环
  19. $arr4 = [
  20. [
  21. 'name'=>'朱老师',
  22. 'age'=>'19岁',
  23. 'job'=>'php讲师',
  24. 'course'=>['html','css']
  25. ],
  26. [
  27. 'name'=>'欧阳克',
  28. 'age'=>'18岁',
  29. 'job'=>'php讲师',
  30. 'course'=>['php','js']
  31. ]
  32. ];
  33. foreach($arr4 as $v){
  34. echo '姓名:'.$v['name'].'--';
  35. echo '年龄:'.$v['age'].'--';
  36. echo '职业:'.$v['job'].'--';
  37. echo '技能:';
  38. foreach($v['course'] as $vv){
  39. echo $vv.'-';
  40. }
  41. echo '<hr>';
  42. }
  43. ?>

运行效果

手抄部分




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