Join 2 array without using merge or foreach

0

The problem is explained simply, I have two arrays:

array(0,1,2,3,4);
array(5,6,7,8,9);

I need both arrays to make one only:

array(0,1,2,3,4,5,6,7,8,9)

But I can not use foreach or while, since they are arrays that contain at least 100 records and that delays the response time, I would like to know if PHP has any native function that does it, something like this:

unir_array(array,array);

I do not know, I always search in English on Google but until now I can not achieve it.

    
asked by Arcaela 29.10.2018 в 03:55
source

2 answers

0

You can use array_merge () which combines the arrays you want, you just have to put them as parameters:

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

Or join them by "concatenation" with the use of the + operator:

$array3 = $array1 + $array2;

Check out the PHP documentation , where it's best explained, greetings.

    
answered by 29.10.2018 в 04:10
0

It is the solution with better performance that occurred to me.

$final = $array_a+array_combine(range(count($array_a),count($array_b)), $array_b);
    
answered by 29.10.2018 в 04:25