我在$data
Array
(
[name] => JimBob
[data] => Array
(
[0] => Array
(
[date] => 2013-15-5
[pole] => 2
[race] => 43
)
[1] => Array
(
[date] => 2013-15-6
[pole] => 15
[race] => 34
)
[2] => Array
(
[date] => 2013-15-7
[pole] => 9
[race] => 54
)
)
)
我需要创建一个看起来像这样的新数组
Array
(
[name] => JimBob
[data] => Array
(
[0] => 2013-15-5,2
[1] => 2013-15-6,15
[2] => 2013-15-7,9
)
)
到目前为止,我有这个array_map函数
$arr2['data'] = array_map(function($date) {
return $date['date'];
}, $data['data']);
print_r($arr2);
哪个输出如下,如何将这些日期添加的极点值用逗号分隔?
Array
(
[data] => Array
(
[0] => 2013-15-5
[1] => 2013-15-6
[2] => 2013-15-7
)
)
答案 0 :(得分:3)
使用连接。
$arr2['data'] = array_map(function($date) {
return $date['date'] . ',' . $date['pole'];
}, $data['data']);