Blogger Information
Blog 2
fans 0
comment 0
visits 1426
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11月11日 上课作业PHP
易开网-水手
Original
397 people have browsed it

创建数组

  1. <?php
  2. $arr1=array(
  3. '欧阳',
  4. '张三',
  5. '李四'
  6. );
  7. ?>

关联数组与索引数组

  1. 用数字作为键名的数组一般叫做索引数组。用字符串表示键的数组就是下面要介绍的关联数组。

索引数组

  1. <?php
  2. //索引数组
  3. $arr1 = array['0'=>'小张', '1'=>'小刘',2=>'小于'];
  4. //关联数组
  5. $arr1 = array['IT1'=>'小张', 'IT2'=>'小刘','IT3'=>'小于'];
  6. ?>

访问数组的数据

  1. <?php
  2. $arr1=array(
  3. '欧阳',
  4. '张三',
  5. '李四'
  6. );
  7. // var_dump($arr1);
  8. print_r($arr1);

二维三维数组及循环

  1. <?php
  2. $arr2=[
  3. '200001'=>'黄浦',
  4. '200002'=>'徐汇',
  5. '200003'=>'嘉定'
  6. ];
  7. // print_r($arr2);
  8. // print_r($arr2[200001]);
  9. // echo $arr2[ 200002 ];
  10. // print_r($arr1[1]);
  11. $arr3 = [
  12. 'name'=>'Xiao hu',
  13. 'age'=>'28',
  14. 'job'=>[
  15. 'coding',
  16. 'cleaning',
  17. 'service'
  18. ]
  19. ];
  20. // print_r( $arr3['name']);
  21. $arr4 = [
  22. [
  23. 'name'=>'Ouyang',
  24. 'age'=>'28',
  25. 'job'=>'it'
  26. ],
  27. $arr3,
  28. [
  29. 'name'=>'Hu lao shi',
  30. 'age'=>'38',
  31. 'job'=>'it2'
  32. ]
  33. ];
  34. // print_r($arr4[1]['name']);
  35. //output Xiao hu
  36. foreach ( $arr4 as $v ){
  37. print_r( $v['name'] );
  38. foreach( $v['job'] as $vzzv){
  39. echo '--'.$vv.'--';
  40. }
  41. echo '<hr />';
  42. }
Correcting teacher:查无此人查无此人

Correction status:unqualified

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