How is the position of a $subject_array pointer determined in a preg_replace_callback's callback function? I.e. What is the numeric key? e.g.
$final_array = preg_replace_callback("/pattern/",
create_function(
'$matches',
'[WHAT IS MY ARRAY POSITION? ($foo = ...)]; return $foo);'
), $subject_array);
EDIT
I want Foo, Bar, baZ. The following doesn't work:
$rgData = array('foo', 'bar', 'baz');
$rgData = preg_replace_callback('/(\w)(\w)(\w)/',
function($rgMatches) use (&$rgData)
{
var_dump(key($rgData));//see this debug
next($rgData);
if (key($rgData)==2) {
return strtoupper($rgMatches[2]);
} else {
return strtoupper($rgMatches[0]);
}
}, $rgData);
var_dump($rgData);//see this debug
or maybe more simply, I want Foo, bAr, baZ:
$rgData = array('foo', 'bar', 'baz');
$rgData = preg_replace_callback('/(\w)(\w)(\w)/',
function($rgMatches) use (&$rgData)
{
var_dump(key($rgData));//see this debug
next($rgData);
return strtoupper($rgMatches[key($rgData)]);
}, $rgData);
var_dump($rgData);//see this debug