2

I have following array,

Array
(
    [14289] => Array
        (
            [0] => Ability||STROKE CLINIC,Session||Session #3: Tues June 28th - Fri July 8th (9-2:00PM),Time||#1 only: 2pm,child1||FC
            [1] => Ability||N/S++,Session||Session #3: Tues June 28th - Fri July 8th (9-2:00PM),Time||#1 only: 2pm,child2||SC
            [2] => Ability||B-,Session||Session #3: Tues June 28th - Fri July 8th (9-2:00PM),Time||#1 only: 2pm,child3||TC
        )

    [14279] => Array
        (
            [0] => Ability||STROKE CLINIC,Session||Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time||#1 only: 1pm,child1||FC
            [1] => Ability||N/S++,Session||Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time||#1 only: 1pm,child2||SC
            [2] => Ability||B-,Session||Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time||#1 only: 1pm,child3||TC
        )

    [14284] => Array
        (
            [0] => Ability||STROKE CLINIC,Session||Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time||#1 only: 1:30pm,child1||FC
            [1] => Ability||N/S++,Session||Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time||#1 only: 1:30pm,child2||SC
        )

)

i need this array as below,

Array
(


            [0] => Ability||STROKE CLINIC,Session||Session #3: Tues June 28th - Fri July 8th (9-2:00PM),Time||#1 only: 2pm,child1||FC
            [1] => Ability||N/S++,Session||Session #3: Tues June 28th - Fri July 8th (9-2:00PM),Time||#1 only: 2pm,child2||SC
            [2] => Ability||B-,Session||Session #3: Tues June 28th - Fri July 8th (9-2:00PM),Time||#1 only: 2pm,child3||TC
            [3] => Ability||STROKE CLINIC,Session||Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time||#1 only: 1pm,child1||FC
            [4] => Ability||N/S++,Session||Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time||#1 only: 1pm,child2||SC
            [5] => Ability||B-,Session||Session #1: Tues May 31st - Fri June 10th (1-5:30PM),Time||#1 only: 1pm,child3||TC          
            [6] => Ability||STROKE CLINIC,Session||Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time||#1 only: 1:30pm,child1||FC
            [7] => Ability||N/S++,Session||Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time||#1 only: 1:30pm,child2||SC


)

How can i do this?

hakre
  • 193,403
  • 52
  • 435
  • 836
Ravichandran Jothi
  • 3,028
  • 11
  • 52
  • 82

4 Answers4

10
$result = array();
foreach($array as $item) {
    $result = array_merge($result, $item);
}
Treffynnon
  • 21,365
  • 6
  • 65
  • 98
4

You're looking for array_merge to merge the (sub-) arrays. This can be called via call_user_func_array for an easy interface:

$result = call_user_func_array('array_merge', $array);

See as well:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
1
$new_arr = array();
array_walk_recursive($arr, function($item) use(&$new_arr)
{
    $new_arr[] = $item;
});
0

Considering your array is :

$z = array(
               '14289' =>
               array('a',
                     'b',
                     'c'
                    ),
               '14290' =>
               array('d',
                     'e',
                     'f'
                    ),
               '14291' =>
               array('g',
                     'h',
                     'i'
                    )
              );

then,

$y =array();// use a blank array to get your result
array_map(function($a) use(&$y){ $y = array_merge( $y,array_values($a)); },$z);

var_dump($y);
SRB
  • 1,031
  • 10
  • 16