本文实例讲述了php数组函数array_push()、array_pop()及array_shift()简单用法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?php /** * array_push()将一个或多个单元压入数组的末尾(入栈) */ $stack = array ( "Java" , "Php" , "C++" ); array_push ( $stack , "C#" , "Ruby" , array ( 'jsp' , 'Asp' )); print_r( $stack ); echo "=====================================" . "<br>" ; /** * array_pop() 将数组最后一个单元弹出(出栈) */ $stack = array ( "Java" , "Php" , "C++" , "C#" , "Ruby" ); array_pop ( $stack ); print_r( $stack ); echo "=====================================" . "<br>" ; /** * array_shift()将数组开头的单元移出数组 array_unshift()在数组开头插入一个或多个单元 */ $stack = array ( "Java" , "Php" , "C++" , "C#" , "Ruby" ); array_shift ( $stack ); print_r( $stack ); ?> |
运行结果如下:
Array
(
[0] => Java
[1] => Php
[2] => C++
[3] => C#
[4] => Ruby
[5] => Array
(
[0] => jsp
[1] => Asp
))
=====================================
Array
(
[0] => Java
[1] => Php
[2] => C++
[3] => C#
)
=====================================
Array
(
[0] => Php
[1] => C++
[2] => C#
[3] => Ruby
)
希望本文所述对大家PHP程序设计有所帮助。
原文链接:https://blog.csdn.net/lzwjavaphp/article/details/6973618