note 97778 added to function.str-replace

From: Date: Fri, 07 May 2010 12:06:12 +0000
Subject: note 97778 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-169046@lists.php.net to get a copy of this message
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; } ---- Server IP: 69.147.83.197 Probable Submitter: 193.178.141.187 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/97778 Del: integrated -- https://master.php.net/note/delete/97778/integrated Del: useless -- https://master.php.net/note/delete/97778/useless Del: bad code -- https://master.php.net/note/delete/97778/bad+code Del: spam -- https://master.php.net/note/delete/97778/spam Del: non-english -- https://master.php.net/note/delete/97778/non-english Del: in docs -- https://master.php.net/note/delete/97778/in+docs Del: other reasons-- https://master.php.net/note/delete/97778 Reject -- https://master.php.net/note/reject/97778 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169046) next »