Re: Extension for str_replace / preg_replace with arrays

From: Date: Thu, 20 Dec 2012 16:31:39 +0000
Subject: Re: Extension for str_replace / preg_replace with arrays
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-64382@lists.php.net to get a copy of this message
On 12/19/12 10:30 PM, Christopher Jones wrote:
On 12/19/2012 03:18 PM, Larry Garfield wrote:
You could likely simplify the code even further using an infinite iterator: http://us1.php.net/infiniteiterator $result = preg_replace_callback(
     '/word/',
     function($matches) use (&$replacements_iterator) {
         return $replacements->next();
     },
     'word word word word word'
); --Larry Garfield
What am I missing that causes the first call to $replacements_iterator->current() to return NULL unless the iterator is rewound before use?
Eh, nothing. You're right, next() doesn't return an element, it just advances, so you still need the current() call. Which seems kinda silly to me, but whatev. --Larry Garfield

« previous php.internals (#64382) next »