note 91035 added to control-structures.foreach

From: Date: Thu, 21 May 2009 16:49:55 +0000
Subject: note 91035 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-155855@lists.php.net to get a copy of this message
/* This is a function for made recursive str_replaces in an array */ function recursive_array_replace($find, $replace, &$data) { if (is_array($data)) { foreach ($data as $key => $value) { if (is_array($value)) { recursive_array_replace($find, $replace, $data[$key]); } else { $data[$key] = str_replace($find, $replace, $value); } } } else { $data = str_replace($find, $replace, $data); } } $a = array(); $a['a'] = "a"; $a['b']['a'] = "ba"; $a['b']['b'] = "bb"; $a['c'] = "c"; $a['d']['a'] = "da"; $a['d']['b'] = "db"; $a['d']['c'] = "dc"; $a['d']['d'] = "dd"; echo "Before Replaces"; print_r($a); recursive_array_replace("a", "XXXX", $a); echo "After Replaces"; print_r($a); ---- Server IP: 130.206.1.5 Probable Submitter: 91.117.99.239 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/91035 Del: integrated -- https://master.php.net/note/delete/91035/integrated Del: useless -- https://master.php.net/note/delete/91035/useless Del: bad code -- https://master.php.net/note/delete/91035/bad+code Del: spam -- https://master.php.net/note/delete/91035/spam Del: non-english -- https://master.php.net/note/delete/91035/non-english Del: in docs -- https://master.php.net/note/delete/91035/in+docs Del: other reasons-- https://master.php.net/note/delete/91035 Reject -- https://master.php.net/note/reject/91035 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#155855) next »