note 97778 deleted from function.str-replace by danbrown

From: Date: Fri, 07 May 2010 12:29:15 +0000
Subject: note 97778 deleted from function.str-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169047@lists.php.net to get a copy of this message
Note Submitter: elvislicsari att yahoo dott com ---- Here is a remake for the function provided by moz667 at gmail dot com. This one is made so that the array's keys can be also replaced. Really useful when you have values with space in the name of a input field and you don't want your key to be replaced by the default "_". function recursive_array_replace($find, $replace, $data) { if (is_array($data)) { foreach ($data as $key => $value) { $newKey = str_replace($find, $replace, $key); if (substr_count($key, " ") > 0) { $data[$newKey] = $value; unset($data[$key]); } if (is_array($value)) { $data[$newKey] = recursive_array_replace($find, $replace, $value); } else { $data[$newKey] = str_replace($find, $replace, $value); } } } else { $data = str_replace($find, $replace, $data); } return $data; }

« previous php.notes (#169047) next »