php - Sum array value per day in multidimensional array

前端 未结 3 432
野的像风
野的像风 2021-01-26 09:52

There are a number of great Q&As on Stackoverflow on how to sum across a multidimensional associative array but I have not found a working example of doing subtotals within

3条回答
  •  执念已碎
    2021-01-26 10:04

    You could do this using array_map() and array_sum():

    $output = array_map(function($a) { 
        return is_array($a) ? array_sum($a) : $a; 
    }, $myArray);
    

    Here's a demo

提交回复
热议问题