0

I'm trying to merge 2 arrays without losing values:

$a = array('one', 'two', 'three');
$b = array('four', 'five', 'six');

The result I need is:

array('one', 'two', 'three', 'four', 'five', 'six');

I know this could be done using a loop + [] operator but it seems like a common task and I'm looking for a simpler solution, maybe using build in array functions. Any suggestions?

4 Answers 4

3

Syntax : array array_merge ( array $array1 [, array $... ] )

array_merge($a,$b);

http://php.net/manual/en/function.array-merge.php

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

Comments

1

You can use array_merge(); function like :

$result = array_merge($array1, $array2);

Comments

0

array_merge() should do the trick.

Comments

0

array array_merge ( array $array1 [, array $... ] )

http://php.net/manual/en/function.array-merge.php

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.