vb.net数组 PHP使用数组实现队列

WBOY
Release: 2016-07-29 08:47:57
Original
1291 people have browsed it

PHP中将数组当做一个栈,主要是使用array_push()和array_pop()两个系统函数来完成。入栈主要是利用array_push()函数向第一个参数的数组尾部添加一个或多个元素,然后返回新数组的长度,示例如下:
而PHP中,将数组当作是队列则主要是用array_push()和array_shift()实现。

复制代码 代码如下:


$zhan=array("WEB");//声明一个数组当做队列
array_push($zhan,"PHP");//将字符串压入栈(数组)中
array_push($zhan,"WWW.CHHUA.COM");//再压入一个元素
print_r($zhan);//打印数组内容
?>


出栈主要是利用array_shift()函数将数组的第一个元素弹出,并将数组的长度减1,示例如下:

复制代码 代码如下:


$zhan=array("WEB","www.chhua.com","WEB开发笔记","PHP","网站建设");//声明一个数组当做栈
array_shift($zhan);//将字符串出队(数组)中
print_r($zhan);//打印数组内容 Array([0] => WEB[1] => www.chhua.com[2] => WEB开发笔记[3] => PHP)
?>

以上就介绍了vb.net数组 PHP使用数组实现队列,包括了vb.net数组方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!