What is wrong in my code:
$i = new RegexIterator(
new ArrayIterator(array(
'test1'=>'test888',
'test2'=>'what?',
'test3'=>'test999')),
'/^test(.*)/',
RegexIterator::REPLACE);
foreach ($i as $name=>$value)
echo $name . '=>' . $value . "\n";
The iterator is empty, why? Thanks for your help!
If you ommit the operation mode (3rd parameter in your new RegexIterator statement) you'll get the matching values, like so:
$array = array('test1' => 'test888', 'test2' => 'what?', 'test3' => 'test999');
$pattern = '/^test(.*)/';
echo '<pre>';
echo "DEFAULT\n";
$arrayIterator = new ArrayIterator($array);
$regexIterator = new RegexIterator($arrayIterator, $pattern);
foreach ($regexIterator as $value) {echo "$value\n";}
echo '</pre>';
You can play with the different operation modes, depending on what you want. Go read up on the setMode documentation: http://www.php.net/manual/en/regexiterator.setmode.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With