How can I merge two arrays while preserving their original keys and avoiding duplicates in PHP?
I have two arrays:
$array1 = array(
'56' => '56',
'57' => '57',
'58' => '58',
'59' => '59',
'60' => '60',
);
$array2 = array(
'58' => '58',
'59' => '59',
'60' => '60',
'61' => '61',
'62' => '62',
);
I would like to merge these two arrays into a single array, while preserving their original keys, and avoiding duplicates. The desired output is:
$output = array(
'56' => '56',
'57' => '57',
'58' => '58',
'59'=> '59',
'60' => '60',
'61' => '61',
'62' => '62'
);
I have tried using array_merge
but it changes the original keys. I also tried using array_combine
, but it does not seem to be working.