If you came here looking for a function to recursively find and replace (scalar) values in an array (also recurses through objects):
<?php
define('RECURSIVE_REPLACE_MARKER', 'recursive_replace_r47yr74yr7623t74r3645236rtvghdcbnsgxbt67g5e21873891');
/**
* Recursively replaces scalar values in objects and arrays. The passed array or object is altered in place.
* @param mixed $data An object or array.
* @param mixed $find The scalar value to find.
* @param mixed $replace The value to replace with (need not be a scalar).
*/
function recursive_replace(&$data, $find, $replace){
if(is_array($data)) {
if (!isset($data[RECURSIVE_REPLACE_MARKER])) {
$data[RECURSIVE_REPLACE_MARKER] = TRUE;
foreach($data as $key=>$val) {
if(is_array($data[$key]) || is_object($data[$key])) {
recursive_replace($data[$key], $find, $replace);
}
else{
if($data[$key] === $find) {
$data[$key] = $replace;
}
}
}
unset($data[RECURSIVE_REPLACE_MARKER]);
}
}
elseif (is_object($data)) {
if (!isset($data->RECURSIVE_REPLACE_MARKER)) {
$data->RECURSIVE_REPLACE_MARKER = TRUE;
foreach($data as $key=>$val) {
if(is_array($data->$key) || is_object($data->$key)){
recursive_replace($data->$key, $find, $replace);
}else{
if($data->$key === $find) {
$data->$key = $replace;
}
}
}
unset($data->RECURSIVE_REPLACE_MARKER);
}
}
}
?>