note 124748 added to function.array-merge

From: Date: Mon, 24 Feb 2020 06:05:22 +0000
Subject: note 124748 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-214211@lists.php.net to get a copy of this message
<?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. ?> ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 182.160.98.85) ---- Manual Page -- http://php.net/manual/en/function.array-merge.php Edit -- https://master.php.net/note/edit/124748 Del: integrated -- https://master.php.net/note/delete/124748/integrated Del: useless -- https://master.php.net/note/delete/124748/useless Del: bad code -- https://master.php.net/note/delete/124748/bad+code Del: spam -- https://master.php.net/note/delete/124748/spam Del: non-english -- https://master.php.net/note/delete/124748/non-english Del: in docs -- https://master.php.net/note/delete/124748/in+docs Del: other reasons-- https://master.php.net/note/delete/124748 Reject -- https://master.php.net/note/reject/124748 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214211) next »