Welcome Guest, Not a member yet? Register   Sign In
how to merge two arrays
#1

[eluser]tmengttm[/eluser]
Hi,
i want to merge two array, but how?

Code:
$array1 [ ] = Array ( [0] => Array ( [id] => 1 [name] => "Alice" ))

$array2 [] = Array ( [0] => Array ( [age] => 22 ));

The result array i want to get:
$result  = Array ( [0] => Array ( [id] => 1   [name] => "Alice"     [age] => 22) );

anyone could help?


#2

[eluser]dnc[/eluser]
You can use array_merge

Code:
$array1 = array(
    "id" => "1",
    "name" => "Alice",
);



$array2 = array(
    "age" => "22",
);



$final_array = array_merge($array1, $array2);
print_r ($final_array);
#3

[eluser]Aken[/eluser]
The vast wealth of Google hath gone unused yet again.
#4

[eluser]tmengttm[/eluser]
hey, thanks for the reply, but my array is not like the one u write @dnc. I know array_merge. but because of the format of my array, i cannot apply it in that simple way.
#5

[eluser]Pedro Luz[/eluser]
best way that i use to do that

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




Theme © iAndrew 2016 - Forum software by © MyBB