Consider this:
<?php
header('Content-Type: text/plain; charset=utf-8');
$sequentialArray = [ 123, 'Jonh'];
$associativeArray = ['ID' => '321', 'name' => 'Paul', 'lastName' => 'Wood'];
$keys = array_slice(
array_keys($associativeArray),
0,
count($sequentialArray)
);
print_r(
array_merge(
$associativeArray,
array_combine($keys, $sequentialArray)
)
);
?>
Output:
Array
(
[ID] => 123
[name] => Jonh
[lastName] => Wood
)
Further reading: Array functions @ php.net.
UPDv1:
Here is function:
<?php
header('Content-Type: text/plain; charset=utf-8');
$sequentialArray = [ 123, 'Jonh'];
$associativeArray = ['ID' => '321', 'name' => 'Paul', 'lastName' => 'Wood'];
function mergeArray($assoc, $seq){
$keys = array_slice(array_keys($assoc), 0, count($seq));
return array_merge($assoc, array_combine($keys, $seq));
}
print_r(mergeArray($associativeArray, $sequentialArray));
?>