©
本文檔使用 php中文網手册 發布
(PHP 5 >= 5.3.0)
SplDoublyLinkedList::push — Pushes an element at the end of the doubly linked list
$value
)
Pushes value
at the end of the doubly linked list.
value
The value to push.
没有返回值。
[#1] Gilles A [2014-09-30 14:18:59]
Be careful SplStack mode is LIFO (Last In First Out) not FIFO (First in First Out)
<?php
// Array (FIFO)
$stack = array();
array_push($stack,"orange");
array_push($stack,"banana");
array_push($stack,"apple");
array_push($stack,"raspberry");
var_dump($stack);
?>
// result
array (size=4)
0 => string 'orange' (length=6)
1 => string 'banana' (length=6)
2 => string 'apple' (length=5)
3 => string 'raspberry' (length=9)
<?php
// SplStack (LIFO)
$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();
}
?>
//result
string 'raspberry' (length=9)
string 'apple' (length=5)
string 'banana' (length=6)
string 'orange' (length=6)