note 27739 rejected from function.array-merge-recursive by didou

From: Date: Mon, 06 Oct 2003 15:56:48 +0000
Subject: note 27739 rejected from function.array-merge-recursive by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57900@lists.php.net to get a copy of this message
Note Submitter: howl@online.no ---- 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

« previous php.notes (#57900) next »