xref: /PHP-8.3/ext/spl/tests/dllist_002.phpt (revision a555cc0b)
1--TEST--
2SPL: DoublyLinkedList: iterators
3--FILE--
4<?php
5$dll = new SplDoublyLinkedList();
6$dll->push(2);
7$dll->push(3);
8$dll->push(4);
9
10$dll2 = clone $dll;
11
12// std iterator
13foreach($dll as $k=>$v) {
14    echo "$k=>$v\n";
15    // inner iterator
16    foreach($dll as $k2=>$v2) {
17        echo "->$k2=>$v2\n";
18    }
19}
20
21echo "# deleted\n";
22
23foreach($dll as $k=>$v) {
24    echo "$k=>$v\n";
25    unset($dll);
26}
27
28echo "# while popping\n";
29
30foreach($dll2 as $k=>$v) {
31    echo "$k=>$v\n";
32    echo "popped ".$dll2->pop()."\n";
33}
34
35?>
36--EXPECT--
370=>2
38->0=>2
39->1=>3
40->2=>4
411=>3
42->0=>2
43->1=>3
44->2=>4
452=>4
46->0=>2
47->1=>3
48->2=>4
49# deleted
500=>2
511=>3
522=>4
53# while popping
540=>2
55popped 4
561=>3
57popped 3
58