note 75714 added to function.str-replace

From: Date: Wed, 13 Jun 2007 01:47:20 +0000
Subject: note 75714 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-127433@lists.php.net to get a copy of this message
The function provided by Toby has a slight flaw. If you start with $arr=array(1=>array('Flowers','Candy'),2=>array()) and perform str_replace_array('Flowers','Flower',$arr) You will end up with only array(1=>array('Flower','Candy')) Here is a version that allows for empty arrays: function str_replace_array ($search, $replace, $subject) { if (is_array($subject)) { foreach ($subject as $id=>$inner_subject) { $subject[$id]=str_replace_array($search, $replace, $inner_subject); } } else { $subject=str_replace($search, $replace, $subject); } return $subject; } ---- Server IP: 69.147.83.197 Probable Submitter: 76.166.58.217 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/75714 Del: integrated -- https://master.php.net/note/delete/75714/integrated Del: useless -- https://master.php.net/note/delete/75714/useless Del: bad code -- https://master.php.net/note/delete/75714/bad+code Del: spam -- https://master.php.net/note/delete/75714/spam Del: non-english -- https://master.php.net/note/delete/75714/non-english Del: in docs -- https://master.php.net/note/delete/75714/in+docs Del: other reasons-- https://master.php.net/note/delete/75714 Reject -- https://master.php.net/note/reject/75714 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127433) next »