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?
$result = array();
foreach($array as $item) {
$result = array_merge($result, $item);
}
hakre
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:
$new_arr = array();
array_walk_recursive($arr, function($item) use(&$new_arr)
{
$new_arr[] = $item;
});
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);
来源:https://stackoverflow.com/questions/9413583/how-to-combine-array-of-array-values-into-one-array