Need Help Merging Arrays

Hello,
I am trying to merge the arrays outputted from GetPersonSubPractices into one array.


<?php
$i = 0;
while($i < count($practices)){
    $sub_practices = $obj->GetPersonSubPractices($practices[$i]['practice_id']);
    $i++;
}
?>

The output of GetPersonSubPractices is a multi-dimensional array that looks like this:

$sub_practices = array( 

0 => array('practice_id' => 4, 'practice_order' => 1, 'practice_order' => 5, 'practice_name' => "Bankruptcy and Workouts", 'practice_url_name' => "bankruptcy-workouts"),

1 => array('practice_id' => 13, 'practice_order' => 3, 'practice_order' => 5, 'practice_name' => "Receiverships", 'practice_url_name' => "receiverships"),

2 => array('practice_id' => 1, 'practice_order' => 4, 'practice_order' => 5, 'practice_name' => "Banking and Financial Institutions", 'practice_url_name' => "banking-financial-institutions")

);

With the code that I have, how do I use array_merge() to combine all my arrays in the while loop?

Any help really appreciated.

Thanks.

I believe this is what you would want using array_merge

<?php
$i = 0;
$allPractices = array();
while($i < count($practices)){
    array_merge($allPractices, $obj->GetPersonSubPractices($practices[$i]['practice_id']));
    $i++;
}
?>

cpradio,
Thanks for the response, but it didn’t work. I want all the arrays of $obj->GetPersonSubPractices to be combined into one array. When I run your code $allPractices is empty. Any other ideas?

Sorry, I misread the documentation on php.net

<?php
$i = 0;
$allPractices = array();
while($i < count($practices)){
    $allPractices = array_merge($allPractices, $obj->GetPersonSubPractices($practices[$i]['practice_id']));
    $i++;
}
?>

That worked! Thanks cpradio!

could be cleaned up a little with a foreach, but otherwise it’s the easiest way i can think of… was trying to push it around a bit with array_map and array_walk, but it’s the old inside-out problem all over again.