小心 SplStack 模式是 LIFO(后进先出),而不是 FIFO(先进先出)
<?php
$stack = array();
array_push($stack,"orange");
array_push($stack,"banana");
array_push($stack,"apple");
array_push($stack,"raspberry");
var_dump($stack);
?>
// 结果
数组 (大小: 4)
0 => 字符串 'orange' (长度: 6)
1 => 字符串 'banana' (长度: 6)
2 => 字符串 'apple' (长度: 5)
3 => 字符串 'raspberry' (长度: 9)
<?php
$stack = new SplStack();
$stack ->push('orange');
$stack ->push('banana');
$stack ->push('apple');
$stack->push('raspberry');
$stack->rewind();
while($stack->valid()){
var_dump($stack->current());
$stack->next();
}
?>
//结果
字符串 'raspberry' (长度: 9)
字符串 'apple' (长度: 5)
字符串 'banana' (长度: 6)
字符串 'orange' (长度: 6)