Blogger Information
Blog 62
fans 3
comment 1
visits 29544
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php数组函数整理
kiraseo_wwwkiraercom
Original
314 people have browsed it

php数组函数整理

代码如下

  1. <?php
  2. echo "array_combine通过合并两个数组来创建一个新数组。<br/>";
  3. $name=['小明', '小王' ,'老李'];
  4. $age = [18,17,26];
  5. echo "<pre>";
  6. var_dump(array_combine($name,$age));
  7. echo "</pre>";
  8. echo "<hr/>";
  9. echo "shuffle打乱数组。<br/>";
  10. echo "默认顺序<br/>";
  11. echo "<pre>";
  12. var_dump($name);
  13. echo "</pre>";
  14. echo "<br/>";
  15. shuffle($name);
  16. echo "<pre>";
  17. var_dump($name);
  18. echo "</pre>";
  19. echo "循环后输出<br/>";
  20. foreach ($name as $v) {
  21. echo "$v ";
  22. }
  23. echo "<hr/>";
  24. echo "sizeof 是sizeof — count() 的别名 <br/>";
  25. $shuiguo = ['西瓜','木瓜','哈密瓜','山竹','樱桃','香蕉','芒果','火龙果'];
  26. echo "输出原数组<br/>";
  27. echo "<pre>";
  28. var_dump($shuiguo);
  29. echo "</pre>";
  30. echo sizeof($shuiguo);
  31. echo "<hr/>";
  32. echo "array_key_last — 获取一个数组的最后一个键值,,重点是取“键”<br/>";
  33. echo "使用函数array_key_last与 函数end的对比效果<br/>";
  34. echo "输出原数组<br/>";
  35. echo "<pre>";
  36. var_dump($shuiguo);
  37. echo "</pre>";
  38. echo array_key_last($shuiguo)."---使用函数array_key_last得到<br/>";
  39. echo end($shuiguo)."---使用函数end得到<br/>";
  40. echo "<hr/>";
  41. echo "交换数组中的键和值。<br/>";
  42. $arr1= [ "a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"];
  43. $flipped = array_flip($arr1);
  44. echo "原数组<br/>";
  45. echo "<pre>";
  46. var_dump($arr1);
  47. echo "</pre>";
  48. echo "使用array_flip函数处理过的数组<br/>";
  49. echo "<pre>";
  50. var_dump($arr1);
  51. echo "</pre>";

输出效果

1.array_combine通过合并两个数组来创建一个新数组

2.shuffle打乱数组

3.sizeof 是sizeof — count() 的别名

4.array_key_last — 获取一个数组的最后一个键值,,重点是取“键”

5.交换数组中的键和值。

Correcting teacher:PHPzPHPz

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