Как объединить массив значений массива в один массив? - PullRequest
2 голосов
/ 23 февраля 2012

У меня есть следующий массив,

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
        )

)

Мне нужен этот массив, как показано ниже,

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


)

Как я могу это сделать?

Ответы [ 4 ]

10 голосов
/ 23 февраля 2012
$result = array();
foreach($array as $item) {
    $result = array_merge($result, $item);
}
3 голосов
/ 23 февраля 2012

Вы ищете array_merge для объединения (под) массивов. Это может быть вызвано через call_user_func_array для простого интерфейса:

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

Смотрите также:

1 голос
/ 23 февраля 2012
$new_arr = array();
array_walk_recursive($arr, function($item) use(&$new_arr)
{
    $new_arr[] = $item;
});
0 голосов
/ 05 февраля 2015

Учитывая, что ваш массив:

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

затем,

$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);
...