首页 > 解决方案 > 从数组中查找数据并对数组中可用日期的一些字段求和

问题描述

    [0] => stdClass Object
        (
            [time_a] => 2018-11-12 01:46:30
            [position_a] => 27.554236,77.750984
            [time_b] => 2018-11-12 02:29:28
            [position_b] => 28.039742,77.592578
            [duration] => 42  58 
            [route_length] => 58.37
            [fuel_consumption] => 6.14
            [fuel_cost] => 443.61
        )

    [1] => stdClass Object
        (
            [time_a] => 2018-11-12 02:34:37
            [position_a] => 28.039742,77.592578
            [time_b] => 2018-11-12 02:41:33
            [position_b] => 28.118502,77.575138
            [duration] => 6  56 
            [route_length] => 9.41
            [fuel_consumption] => 0.99
            [fuel_cost] => 71.53
        )

    [2] => stdClass Object
        (
            [time_a] => 2018-11-11 02:58:07
            [position_a] => 28.118502,77.575138
            [time_b] => 2018-11-12 04:20:28
            [position_b] => 28.710197,77.204809
            [duration] => 1  22  21 
            [route_length] => 85.43
            [fuel_consumption] => 8.99
            [fuel_cost] => 649.53
        )

    [3] => stdClass Object
        (
            [time_a] => 2018-11-11 06:16:04
            [position_a] => 28.710197,77.204809
            [time_b] => 2018-11-12 06:48:20
            [position_b] => 28.651432,77.112353
            [duration] => 32  16 
            [route_length] => 14.42
            [fuel_consumption] => 1.54
            [fuel_cost] => 111.27
        )

    [4] => stdClass Object
        (
            [time_a] => 2018-11-13 22:20:20
            [position_a] => 28.651432,77.112353
            [time_b] => 2018-11-12 23:11:16
            [position_b] => 28.497530,77.087215
            [duration] => 50  56 
            [route_length] => 25.82
            [fuel_consumption] => 2.71
            [fuel_cost] => 195.80
        )

    [5] => stdClass Object
        (
            [time_a] => 2018-11-13 23:17:43
            [position_a] => 28.497530,77.087215
            [time_b] => 2018-11-12 23:25:23
            [position_b] => 28.490739,77.073738
            [duration] => 7  40 
            [route_length] => 1.77
            [fuel_consumption] => 0.16
            [fuel_cost] => 11.56
        )

这是一个数组,我想要,2018-11-12 日期存在的fuel_cost 总和,所有日期都相同,这里是三个日期,所以我只想显示三行,fuel_cost 的总和为三个日期。希望我解释得很好,如果有任何遗漏,请纠正我。

标签: phparrays

解决方案


推荐阅读