note 124748 deleted from function.array-merge by salathe

From: Date: Mon, 06 Sep 2021 22:43:57 +0000
Subject: note 124748 deleted from function.array-merge by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216883@lists.php.net to get a copy of this message
Note Submitter: Md. Abutaleb ---- <?php /* Please note that, the array_merge() function replaces the first key by the second key if both arrays contain the same key. But consider the following code where key '3' is string not integer. In that case ('3') is consider as numeric and generating new numeric key instead of replacing by second one to first one */ $array1 = array(0 => 'zero_a', 2 => 'two_a', '3' => 'three_a', 'name' => 'First Name'); $array2 = array(1 => 'one_b', 2 => 'Two b', '3' => 'three_b', 'name' => 'Second Name'); $output = array_merge($array1, $array2); print_r($output); Array ( [0] => zero_a [1] => two_a [2] => three_a [name] => Second Name [3] => one_b [4] => Two b [5] => three_b ) //Hope it will helpful. ?>

« previous php.notes (#216883) next »