Append to an existing array?

Discussion in 'Technology' started by Mirage, Mar 7, 2006.

  1. Mirage

    Mirage Administrator 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.

  2. Mr_Snipes

    Mr_Snipes Registered Member

    The following is how you merge one array into another.

    = array(24);
    $array2 = array("a""b"4);
    $result array_merge($array1$array2);
    The above example will output:

    [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.
  3. Mirage

    Mirage Administrator Staff Member V.I.P.

    Ok, that worked. :)

    That was easier than I thought it would be.

  4. Mr_Snipes

    Mr_Snipes Registered Member

    You are welcome. Glad to be of assistance.

Share This Page