0

I have 2 arrays. I want to combine them.

array 1:

Array
(
[100] => 
[50] => 
[CREDIT] => 14.31
[CHEQUE] => 
)

array 2:

Array
(
[id] => 491
[ce_unique_id] => CE144915960926-21
[company_id] => 1
)

I am getting this result after merging them with array_merge():

Array
(
--->[0] => 
--->[1] => 
[CREDIT] => 14.31
[CHEQUE] => 
[id] => 491
[ce_unique_id] => CE144915960926-21
[company_id] => 1
)

And my expected result is:

Array
(
--->[100] => 
--->[50] => 
[CREDIT] => 14.31
[CHEQUE] => 
[id] => 491
[ce_unique_id] => CE144915960926-21
[company_id] => 1
)

Why the numeric keys are getting changed after merging 2 arrays?

RNK
  • 5,582
  • 11
  • 65
  • 133

1 Answers1

3

array_merge treats numeric keys differently http://php.net/manual/en/function.array-merge.php

However the documentation above suggests that merging using the following should work:

$newArray = $array1 + $array2;
Jim
  • 22,354
  • 6
  • 52
  • 80