Stack Implementation in PHP

Program 1

<html>
<body>
    <center>
<pre>
    
<?php
$mystack=[10,20,30,40,50,60,70,80];

//print_r($mystack);
for($i=0;$i<count($mystack);$i++)
{
    echo "<br>".$mystack[$i];
}
// // push
// array_push($mystack,50);
// echo "<br> After push one element";
// for($i=0;$i<count($mystack);$i++)
// {
//     echo "<br>".$mystack[$i];
// }
 // Pop 
   array_pop($mystack);
   array_pop($mystack);
   array_pop($mystack);
   array_pop($mystack);
   array_pop($mystack);
   array_pop($mystack);
   array_pop($mystack);
   array_pop($mystack);
  
   if(count($mystack)==0)
      echo "<br>Stack is empty";
   else
 {
    echo "<br> After pop one element";   
    for($i=0;$i<count($mystack);$i++) 
  {
     echo "<br>".$mystack[$i];
  }
 }  
?>
</pre>
</center>
</body>
</html>

 

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *