xref: /PHP-8.0/ext/spl/tests/iterator_051.phpt (revision f8d79582)
1--TEST--
2SPL: RegexIterator::GET_MATCH, USE_KEY
3--FILE--
4<?php
5
6class MyRegexIterator extends RegexIterator
7{
8    function show()
9    {
10        foreach($this as $k => $v)
11        {
12            var_dump($k);
13            var_dump($v);
14        }
15    }
16}
17
18$ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6));
19$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY);
20$it->show();
21
22$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY);
23$it->show();
24
25var_dump($ar);
26
27?>
28--EXPECTF--
29string(3) "1,2"
30array(3) {
31  [0]=>
32  string(3) "1,2"
33  [1]=>
34  string(1) "1"
35  [2]=>
36  string(1) "2"
37}
38string(5) "1,2,3"
39array(3) {
40  [0]=>
41  string(3) "1,2"
42  [1]=>
43  string(1) "1"
44  [2]=>
45  string(1) "2"
46}
47int(1)
48array(2) {
49  [0]=>
50  string(1) "1"
51  [1]=>
52  string(1) "1"
53}
54string(3) "1,2"
55array(2) {
56  [0]=>
57  string(1) "1"
58  [1]=>
59  string(1) "1"
60}
61string(5) "1,2,3"
62array(2) {
63  [0]=>
64  string(1) "1"
65  [1]=>
66  string(1) "1"
67}
68int(0)
69array(2) {
70  [0]=>
71  string(1) "0"
72  [1]=>
73  string(1) "0"
74}
75object(ArrayIterator)#%d (1) {
76  ["storage":"ArrayIterator":private]=>
77  array(7) {
78    [1]=>
79    int(0)
80    ["1,2"]=>
81    int(1)
82    ["1,2,3"]=>
83    int(2)
84    [0]=>
85    int(3)
86    ["FooBar"]=>
87    int(4)
88    [","]=>
89    int(5)
90    [",,"]=>
91    int(6)
92  }
93}
94