Home > Backend Development > PHP Tutorial > Data structure c language version code that uses arrays to implement stack data structures in PHP

Data structure c language version code that uses arrays to implement stack data structures in PHP

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

In the stack, the last data pushed (pushed) will be the first to be popped (popped).
That is, the "first in, last out" data structure is used when storing data.
In PHP, treating an array as a stack is mainly accomplished by using the two system functions array_push() and array_pop().
Pushing onto the stack mainly uses the array_push() function to add one or more elements to the end of the array of the first parameter, and then returns the length of the new array. The example is as follows:

Copy the code The code is as follows:


< ;?php
$zhan=array("WEB");//Declare an array as a stack
array_push($zhan,"PHP");//Push a string into the stack (array)
array_push($zhan, "WWW.CHHUA.COM");//Push in another element
print_r($zhan);//Print the contents of the array
?>


Pop the stack mainly by using the array_pop() function to pop the last function of the array Pop up and reduce the length of the array by 1. The example is as follows:

Copy the code The code is as follows:


$zhan=array("WEB","www.chhua.com"," WEB Development Notes", "PHP", "Website Construction");//Declare an array as a stack
array_pop($zhan);//Pop the string from the stack (array)
print_r($zhan);//Print Array content Array([0] => WEB[1] => www.chhua.com[2] => WEB development notes[3] => PHP)
?>

The above introduces the code of data structure c language version in PHP that uses arrays to implement stack data structures, including the data structure c language version. I hope it will be helpful to friends who are interested in PHP tutorials.

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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template