xref: /PHP-8.2/ext/spl/tests/iterator_055.phpt (revision f8d79582)
1--TEST--
2SPL: RegexIterator::SPLIT, 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::SPLIT, RegexIterator::USE_KEY);
20
21$it->show();
22
23var_dump($ar);
24
25?>
26--EXPECTF--
27string(3) "1,2"
28array(2) {
29  [0]=>
30  string(0) ""
31  [1]=>
32  string(0) ""
33}
34string(5) "1,2,3"
35array(2) {
36  [0]=>
37  string(0) ""
38  [1]=>
39  string(2) ",3"
40}
41object(ArrayIterator)#%d (1) {
42  ["storage":"ArrayIterator":private]=>
43  array(7) {
44    [1]=>
45    int(0)
46    ["1,2"]=>
47    int(1)
48    ["1,2,3"]=>
49    int(2)
50    [0]=>
51    int(3)
52    ["FooBar"]=>
53    int(4)
54    [","]=>
55    int(5)
56    [",,"]=>
57    int(6)
58  }
59}
60