3

Assume we have an array

$a = array('a', 'b', 'c');

We need to get an array

$a = array('a', 'b', 'c', 'd', 'e');

Should we use

$a = array_merge($a, array('d', 'e'));

or

$a[] = 'd';
$a[] = 'e';
0

3 Answers 3

3

both are identical in this situation since you dont have any ordered or named keys to be concerned about. use whichever you prefer.

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

Comments

1

It depends on how you have the values, you have already as an array, then array_merge() is ok, but if you loop in something and you get a value at a time then the second option is ok.

Comments

0

Depends on how you generate the second array. If the second array you wish to append comes from the output of another function, the better choice is array_merge().

Comments

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.