0

我有以下数组存储在$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
        )

)
4

1 回答 1

3

使用串联。

$arr2['data'] = array_map(function($date) {
    return $date['date'] . ',' . $date['pole'];
}, $data['data']);
于 2013-08-28T04:46:12.907 回答