取消设置偏移量时,该元素将从双向链表中删除。因此,以下代码
<?php
$obj = new SplDoublyLinkedList();
$obj->push(4);
$obj->push(5);
$obj->push(6);
$obj->offsetUnset(1);
echo "Our Linked List:";
print_r($obj);
?>
将输出
Our Linked List:SplDoublyLinkedList Object
(
[flags:SplDoublyLinkedList:private] => 0
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => 4
[1] => 5
[2] => 6
)
)
Our New Linked List:SplDoublyLinkedList Object
(
[flags:SplDoublyLinkedList:private] => 0
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => 4
[1] => 6
)
请注意,索引为 2 的元素现在索引为 1。索引为 1 的原始元素不仅被取消设置了值,而且也从列表中删除了。