Stack in Use : Stack « Data Structure « PHP






Stack in Use

<html>
<head>
<title>Stack</title>
</head>
<body>
<?php
     $stack = array();
   
     $book_one = "One";
     $book_two = "Two";
     $book_three = "Three";
   
     array_push($stack, $book_one);
     array_push($stack, $book_three);
     array_push($stack, $book_two);
   
     $n = count ($stack);
     while ($book = array_pop ($stack)) {
          print ("Item $n: $book<br />\n");
          $n--;
     }
?>
</body>
</html>

           
       








Related examples in the same category

1.array_pop: Pop the element off the end of array
2.array_push: Push one or more elements onto the end of array
3.A stack with type restricted to int