php数组函数array_push()、array_pop()及array_shift()简单用法示例

本文实例讲述了php数组函数array_push()、array_pop()及array_shift()简单用法,分享给大家供大家参考,具体如下:

  1. <?php
  2. /**
  3. * array_push()将一个或多个单元压入数组的末尾(入栈)
  4. */
  5. $stack = array("Java", "Php", "C++");
  6. array_push($stack, "C#", "Ruby", array('jsp', 'Asp'));
  7. print_r($stack);
  8. echo "====================================="."<br>";
  9. /**
  10. * array_pop() 将数组最后一个单元弹出(出栈)
  11. */
  12. $stack = array("Java", "Php", "C++", "C#", "Ruby");
  13. array_pop($stack);
  14. print_r($stack);
  15. echo "====================================="."<br>";
  16. /**
  17. * array_shift()将数组开头的单元移出数组 array_unshift()在数组开头插入一个或多个单元
  18. */
  19. $stack = array("Java", "Php", "C++", "C#", "Ruby");
  20. array_shift($stack);
  21. print_r($stack);
  22. ?>

运行结果如下:

  1. Array
  2. (
  3. [0] => Java
  4. [1] => Php
  5. [2] => C++
  6. [3] => C#
  7. [4] => Ruby
  8. [5] => Array
  9. (
  10. [0] => jsp
  11. [1] => Asp
  12. )
  13. )
  14. =====================================
  15. Array
  16. (
  17. [0] => Java
  18. [1] => Php
  19. [2] => C++
  20. [3] => C#
  21. )
  22. =====================================
  23. Array
  24. (
  25. [0] => Php
  26. [1] => C++
  27. [2] => C#
  28. [3] => Ruby
  29. )