-1

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) ?

5
  • Possible duplicate of What's the difference between array_merge and array + array? Commented Feb 24, 2016 at 15:27
  • 1
    Duplicate of: php.net/manual/en/function.array-merge.php Commented 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) Commented Feb 24, 2016 at 16:53
  • look carefully at $arr1 in left side of operation, and the parameters $arr1 and $arr2 Commented 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. Commented Feb 24, 2016 at 17:02

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

yea but i had completely different keys in those arrays, and one of them wasn't displaying the values of those keys
@ArditMeti Would you care to share your test data so we can replicate your problem? Otherwise there is no way to solve your issue.
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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.