-2

我的代码中有这个数组

Array
(
[0] => Array
    (
        [0] => Roof setting
        [1] => [2013-04-22,7]
    )

[1] => Array
    (
        [0] => Garbage Collection
        [1] => [2013-04-22,22]
    )

[2] => Array
    (
        [0] => Sales Payout
        [1] => [2013-04-22,10]
    )

[3] => Array
    (
        [0] => Sales Payout
        [1] => [2013-04-25,10]
    )

[4] => Array
    (
        [0] => Sales Payout
        [1] => [2013-04-25,10]
    )

[5] => Array
    (
        [0] => Fix cable car2
        [1] => [2013-04-24,77.79]
    )

[6] => Array
    (
        [0] => Fix cable car2
        [1] => [2013-04-25,77.79]
    )

)

现在我想以这样的形式获取这个数组,对于每个重复的标签,它只显示标签一次,并且沿着这些标签多次重复日期。结果应该是这样的

Array
(
    'label': => Roof setting
        (

        'data:' => [2013-04-22,7]
    ),

   'label' => Garbage Collection
    (

        'data': => [2013-04-22,22]
    )

'label' => Sales Payout
    (

       'data:' => [[2013-04-22,10],[2013-04-25,10],[2013-04-25,10]]
    )



   'label' =>Fix cable car2
    (
       'data' => [[2013-04-24,77.79[,2013-04-25,77.79]]
        [1] => [2013-04-24,77.79[
    )
)
4

1 回答 1

0

You could prolly get the result you want with something like this:

foreach($array as $arr)
    $out[$arr[0]][] = $arr[1];

Where $array is your array containing the data.

于 2013-05-02T08:07:26.223 回答