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) ?
-
Possible duplicate of What's the difference between array_merge and array + array?Kyle Pittman– Kyle Pittman2016-02-24 15:27:39 +00:00Commented Feb 24, 2016 at 15:27
-
1Duplicate of: php.net/manual/en/function.array-merge.phpAbraCadaver– AbraCadaver2016-02-24 15:48:46 +00:00Commented Feb 24, 2016 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– Ardit Meti2016-02-24 16:53:34 +00:00Commented Feb 24, 2016 at 16:53
-
look carefully at $arr1 in left side of operation, and the parameters $arr1 and $arr2Ardit Meti– Ardit Meti2016-02-24 16:59:21 +00:00Commented Feb 24, 2016 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– Ardit Meti2016-02-24 17:02:29 +00:00Commented Feb 24, 2016 at 17:02
Add a comment
|
2 Answers
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.
2 Comments
Ardit Meti
yea but i had completely different keys in those arrays, and one of them wasn't displaying the values of those keys
Kyle Pittman
@ArditMeti Would you care to share your test data so we can replicate your problem? Otherwise there is no way to solve your issue.
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
1 Comment
Ardit Meti
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