note 101145 added to function.array-replace

From: Date: Mon, 29 Nov 2010 18:02:51 +0000
Subject: note 101145 added to function.array-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-174446@lists.php.net to get a copy of this message
I got hit with a noob mistake. :) When the function was called more than once, it threw a function redeclare error of course. The enviroment I was coding in never called it more than once but I caught it in testing and here is the fully working revision. A simple logical step was all that was needed. // Polecat's Multi-dimensional array_replace function // Will take all data in second array and apply to first array leaving any non-corresponding values untouched and intact function polecat_array_replace( array &$array1, array &$array2 ) { // This sub function is the iterator that will loop back on itself ad infinitum till it runs out of array dimensions if(!function_exists('tier_parse')){ function tier_parse(array &$t_array1, array&$t_array2) { foreach ($t_array2 as $k2 => $v2) { if (is_array($t_array2[$k2])) { tier_parse($t_array1[$k2], $t_array2[$k2]); } else { $t_array1[$k2] = $t_array2[$k2]; } } return $t_array1; } } foreach ($array2 as $key => $val) { if (is_array($array2[$key])) { tier_parse($array1[$key], $array2[$key]); } else { $array1[$key] = $array2[$key]; } } return $array1; } ---- Server IP: 69.147.83.197 Probable Submitter: 70.241.103.180 ---- Manual Page -- http://www.php.net/manual/en/function.array-replace.php Edit -- https://master.php.net/note/edit/101145 Del: integrated -- https://master.php.net/note/delete/101145/integrated Del: useless -- https://master.php.net/note/delete/101145/useless Del: bad code -- https://master.php.net/note/delete/101145/bad+code Del: spam -- https://master.php.net/note/delete/101145/spam Del: non-english -- https://master.php.net/note/delete/101145/non-english Del: in docs -- https://master.php.net/note/delete/101145/in+docs Del: other reasons-- https://master.php.net/note/delete/101145 Reject -- https://master.php.net/note/reject/101145 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174446) next »