note 27739 added to function.array-merge-recursive

From: Date: Tue, 17 Dec 2002 13:42:06 +0000
Subject: note 27739 added to function.array-merge-recursive
Groups: php.notes 
Request: Send a blank email to php-notes+get-41011@lists.php.net to get a copy of this message
Hello, for merging two or more arrays I've tended to use my own "custom" array_merge(). This array_merge will go straight into the array, and though I'm sure it would end in an endless loop if used on arrays with pointers, it is a nifty function you guys might find nice to use. function array_merge() { $return = null; foreach(func_get_args() as $array) if (is_array($array)) { if (!is_array($return)) { $return = $array; continue; } foreach($array as $var => $val) { if (is_array($val) && isset($return[$var])) $return[$var] = $this->array_merge($return[$var],$val); else $return[$var] = $val; } } return $return; } That function (or rather method) is used to merge arrays, with the last key to be entered to be top ranked. Anyhow, if anyone has got a sollution to the fact that it would break on arrays with endless pointers, please tell me! - Erlend -- http://www.php.net/manual/en/function.array-merge-recursive.php http://master.php.net/manage/user-notes.php?action=edit+27739 http://master.php.net/manage/user-notes.php?action=delete+27739 http://master.php.net/manage/user-notes.php?action=reject+27739

« previous php.notes (#41011) next »