Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a function that merges a bunch of bookings from different groups. I want to make it easier to set the group. Heres the function at the moment:

function groups() {
    $b1 = bookings(1);
    $b2 = bookings(2);

    $merge = array_merge($b1, $b2);
    return $merge;
}

I would like to make it look something like this:

function groups() {
    $merge = bookings(1), bookings(2);
    return $merge;
}

The reason is I would like to only have to edit one place if I would like to add a group. Now you have to add $b3 = bookings(3); on one line and $b3 in the array_merge.

Is this possible?

share|improve this question
    
If i undestand correctly what you need, just make one main array, and push in that one the smaller ones. –  Teris L May 5 at 7:42
3  
It is alredy answered. stackoverflow.com/questions/12397563/… –  Jirka Kopřiva May 5 at 7:42
add comment

1 Answer

up vote 0 down vote accepted

if and only if the arrays have different keys, you can use the + operator to union the two arrays. If the arrays contain the same key (eg. default indexes), only the first one will be kept and the rest will be omitted.

eg:

$arr1 = array("color1" => "red", "color2" => "blue");
$arr2 = array("color1" => "black", "color3" => "green");
$arr3 = $arr1 + $arr2; //result is array("color1" => "red", "color2" => "blue", "color3" => "green");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.