Hey guys is there any difference between the order of parameters when you run $arr1 = array_merge($arr1, $arr2);
versus $arr1 = array_merge($arr2, $arr1)
?
Asked
Active
Viewed 41 times
-1

Ardit Meti
- 571
- 5
- 22
-
Possible duplicate of [What's the difference between array\_merge and array + array?](http://stackoverflow.com/questions/5394157/whats-the-difference-between-array-merge-and-array-array) – Kyle Pittman Feb 24 '16 at 15:27
-
1Duplicate of: http://php.net/manual/en/function.array-merge.php – AbraCadaver Feb 24 '16 at 15:48
-
it is not a duplicate. I was having a problem with those. One of them wasn't displaying the values in some keys, while the other one was displaying it. Those arrays had not a single key in common. Just after the merge some values in one array were missing (empty) – Ardit Meti Feb 24 '16 at 16:53
-
look carefully at $arr1 in left side of operation, and the parameters $arr1 and $arr2 – Ardit Meti Feb 24 '16 at 16:59
-
I tested it locally it is working properly, I just don't know why I was having that strange behavior in my live site. It was very very strange. – Ardit Meti Feb 24 '16 at 17:02
2 Answers
0
Yes, there is. According to Php function description: Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

adomas.m
- 383
- 2
- 12
-
yea but i had completely different keys in those arrays, and one of them wasn't displaying the values of those keys – Ardit Meti Feb 24 '16 at 16:46
-
1@ArditMeti Would you care to share your test data so we can replicate your problem? Otherwise there is no way to solve your issue. – Kyle Pittman Feb 24 '16 at 20:55
0
it is the order when merging array_merge ($ arr1, $ arr2); gives $ arr1 at the beginning and after $ arr2 whereas array_merge ($ arr2, $ arr1); gives $ arr2 at the beginning and after $ arr1

bhrached
- 127
- 1
- 9
-
yea but i had completely different keys in those arrays, and one of them wasn't displaying the values of those keys while the reverse was displaying the values of those keys. I don't know if it's a bug or what... btw those values were same in many keys ex: ['key1'] => test, ['key2'] => test – Ardit Meti Feb 24 '16 at 16:51