how to work with RegexIterator::REPLACE mode?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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! 回答1: 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