本文實例講述了php線性表的入棧與出棧用法。分享給大家供大家參考。具體如下:
1 2 3 4 5 <?php $stack = array("Simon", "Elaine"); //定義數組 array_push($stack, "Helen", "Peter"); //入棧 print_r($stack); ?> 1 2 3 4 5 <?php $stack = array("Simon", "Elaine"); //定義數組 array_unshift ($stack, "Helen", "Peter"); //入棧 print_r($stack); ?> 1 2 3 4 5 <?php $stack = array("Simon", "Elaine", "Helen", "Peter"); echo array_pop($stack)."/n"; //出棧 print_r($stack); ?> 1 2 3 4 5 <?php $stack = array("Simon", "Elaine", "Helen", "Peter"); echo array_shift($stack)."/n"; //出棧 print_r($stack); ?>