Blogger Information
Blog 28
fans 0
comment 1
visits 13335
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
演示数组函数
centos
Original
363 people have browsed it

演示数组函数

栈的操作

  1. <?php
  2. // 栈操作
  3. $arr = [];
  4. // 尾部添加
  5. array_push($arr,'id',1);
  6. printf('<pre>%s<pre>',print_r($arr,true));
  7. echo '<br>';
  8. // 尾部删除
  9. array_pop($arr);
  10. print_r($arr);
  11. // printf('<pre>%s<pre>',print_r($arr,true));
  12. // 头部增加
  13. array_unshift($arr,'name');
  14. print_r($arr);
  15. // 头部删除
  16. array_shift($arr);
  17. print_r($arr);
  18. // 排序按值
  19. // 正常由低到高
  20. $res =[3,6,9,8.9,66,'name','ABC'];
  21. sort($res);
  22. printf('<pre>%s<pre>',print_r($res,true));
  23. // 由高到低
  24. rsort($res);
  25. print_r($res);
  26. // 降序但是索引不变
  27. $res =[3,6,9,8.9,66,'name','ABC'];
  28. arsort($res);
  29. print_r($res);
  30. // 排序按键
  31. // 按键由低到高
  32. $res =["b"=>'bag',"f"=>0,"a"=>3.5];
  33. ksort($res);
  34. print_r($res);
  35. // 按键由高到低
  36. krsort($res);
  37. print_r($res);
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