我有以下数组,
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
)
我该怎么做?
答案 0 :(得分:10)
$result = array();
foreach($array as $item) {
$result = array_merge($result, $item);
}
答案 1 :(得分:3)
您正在寻找合并(子)数组的array_merge
。这可以通过call_user_func_array
调用,以获得简单的界面:
$result = call_user_func_array('array_merge', $array);
参见:
答案 2 :(得分:1)
$new_arr = array();
array_walk_recursive($arr, function($item) use(&$new_arr)
{
$new_arr[] = $item;
});
答案 3 :(得分:0)
考虑你的阵列是:
$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);