note 115429 deleted from function.array-merge-recursive by salathe

From: Date: Tue, 22 Jul 2014 08:07:24 +0000
Subject: note 115429 deleted from function.array-merge-recursive by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-200023@lists.php.net to get a copy of this message
Note Submitter: 858210120 at qq dot com ---- $ar1 = array("color" => array("favorite" => "red", 'like' => 'black1'), 5); $ar2 = array(10, "color" => array("favorite" => "green", "blue")); $ar3 = array(11, "color" => array("favorite" => "yellow", "red", 'like' => 'black')); $result = array_merge_recursive_new($ar1, $ar2, $ar3); var_dump($result); function array_merge_recursive_new() { $arrays = func_get_args(); $base = array(); foreach ($arrays as $array) { if (is_array($array)) { foreach ($array as $key => $value) { // string key if (is_string($key)) { if (is_array($value)) { $base[$key] = array_merge_recursive_new(isset($base[$key])?$base[$key]:array(), $value); }else{ $base[$key] = $value; } } else{ $base[] = $value; } } } } return $base; }

« previous php.notes (#200023) next »