note 48426 deleted from function.array-merge by salathe

From: Date: Mon, 06 Sep 2021 22:47:04 +0000
Subject: note 48426 deleted from function.array-merge by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216907@lists.php.net to get a copy of this message
Note Submitter: Frederick.Lemasson{AT}kik-it.com ---- if you generate form select from an array, you probably want to keep your array keys and order intact, if so you can use ArrayMergeKeepKeys(), works just like array_merge : array ArrayMergeKeepKeys ( array array1 [, array array2 [, array ...]]) but keeps the keys even if of numeric kind. enjoy <? $Default[0]='Select Something please'; $Data[147]='potato'; $Data[258]='banana'; $Data[54]='tomato'; $A=array_merge($Default,$Data); $B=ArrayMergeKeepKeys($Default,$Data); echo '<pre>'; print_r($A); print_r($B); echo '</pre>'; Function ArrayMergeKeepKeys() { $arg_list = func_get_args(); foreach((array)$arg_list as $arg){ foreach((array)$arg as $K => $V){ $Zoo[$K]=$V; } } return $Zoo; } //will output : Array ( [0] => Select Something please [1] => potato [2] => banana [3] => tomato ) Array ( [0] => Select Something please [147] => potato [258] => banana [54] => tomato ) ?>

« previous php.notes (#216907) next »