• Welcome to the PopMalt Forums! Whether you're new to forums or a veteran, welcome to our humble home on the web! We're a 20-year old forum community with thousands of discussions on entertainment, lifestyle, leisure, and more.

    Our rules are simple. Be nice and don't spam. Registration is free, so what are you waiting for? Join today!.

Append to an existing array?

Mirage

Secret Agent
Staff member
V.I.P.
Does anybody know how to add values from an array into an array that has already been defined?

Basically, Array 1 has been opened and closed, now a few sections down I need to enter more variables into the array, but through another array. Obviously I can do this by adding them directly into the firste array, but the second array is being pulled from a separate php file.

I hope that makes sense. If anybody has any ideas I would appreicate it.
 

Mr_Snipes

Registered Member
The following is how you merge one array into another.

PHP:
<?php
$array1 = array(2, 4);
$array2 = array("a", "b", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>
The above example will output:

Array
(
[0] => 2
[1] => 4
[2] => a
[3] => b
[4] => 4
)

array_merge($array1, $array2) takes the values in $array2 and adds them to the back of $array1 and then returns the result as a new array.

Hope this is helpful.
 
Top