note 92224 added to function.array-replace-recursive

From: Date: Tue, 14 Jul 2009 23:16:27 +0000
Subject: note 92224 added to function.array-replace-recursive
Groups: php.notes 
Request: Send a blank email to php-notes+get-158309@lists.php.net to get a copy of this message
Function corrected from below: <? // Joins two or more arrays together recursively; key/value pairs of the first // array are replaced with key/value pairs from the subsequent arrays. Any // key/value pair not present in the first array is added to the final array function array_join() { // Get array arguments $arrays = func_get_args(); // Define the original array $original = array_shift($arrays); // Loop through arrays foreach ($arrays as $array) { // Loop through array key/value pairs foreach ($array as $key => $value) { // Value is an array if (is_array($value)) { // Traverse the array; replace or add result to original array $original[$key] = array_join($original[$key], $array[$key]); } // Value is not an array else { // Replace or add current value to original array $original[$key] = $value; } } } // Return the joined array return $original; } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 209.164.165.25 ---- Manual Page -- http://www.php.net/manual/en/function.array-replace-recursive.php Edit -- https://master.php.net/note/edit/92224 Del: integrated -- https://master.php.net/note/delete/92224/integrated Del: useless -- https://master.php.net/note/delete/92224/useless Del: bad code -- https://master.php.net/note/delete/92224/bad+code Del: spam -- https://master.php.net/note/delete/92224/spam Del: non-english -- https://master.php.net/note/delete/92224/non-english Del: in docs -- https://master.php.net/note/delete/92224/in+docs Del: other reasons-- https://master.php.net/note/delete/92224 Reject -- https://master.php.net/note/reject/92224 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158309) next »