xref: /PHP-7.1/ext/spl/tests/iterator_051.phpt (revision 610c7fbe)
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===DONE===
29<?php exit(0); ?>
30--EXPECTF--
31string(3) "1,2"
32array(3) {
33  [0]=>
34  string(3) "1,2"
35  [1]=>
36  string(1) "1"
37  [2]=>
38  string(1) "2"
39}
40string(5) "1,2,3"
41array(3) {
42  [0]=>
43  string(3) "1,2"
44  [1]=>
45  string(1) "1"
46  [2]=>
47  string(1) "2"
48}
49int(1)
50array(2) {
51  [0]=>
52  string(1) "1"
53  [1]=>
54  string(1) "1"
55}
56string(3) "1,2"
57array(2) {
58  [0]=>
59  string(1) "1"
60  [1]=>
61  string(1) "1"
62}
63string(5) "1,2,3"
64array(2) {
65  [0]=>
66  string(1) "1"
67  [1]=>
68  string(1) "1"
69}
70int(0)
71array(2) {
72  [0]=>
73  string(1) "0"
74  [1]=>
75  string(1) "0"
76}
77object(ArrayIterator)#%d (1) {
78  ["storage":"ArrayIterator":private]=>
79  array(7) {
80    [1]=>
81    int(0)
82    ["1,2"]=>
83    int(1)
84    ["1,2,3"]=>
85    int(2)
86    [0]=>
87    int(3)
88    ["FooBar"]=>
89    int(4)
90    [","]=>
91    int(5)
92    [",,"]=>
93    int(6)
94  }
95}
96===DONE===
97