my array:
$data = [
0 => [
"id" => "23",
"to_user_id" => "6",
"from_user_id" => "1",
"month" => "201810",
"add_time" => "1540795976",
"f1" => 10,"f2" => 0,"f3" => 0,"f4" => 0, "f5" => 0,"f6" => 55,"f7" => 0,"f8" => 0,"f9" => 77,"f10" => 0,"f11" => 0,"f12" => 99,"f13" => 77,"f14" => 66,"f15" => 55,
"score" => 0
],
1 => [
"id" => "24",
"to_user_id" => "6",
"from_user_id" => "1",
"month" => "201810",
"add_time" => "1540795976",
"f1" => 10,"f2" => 0,"f3" => 0,"f4" => 0, "f5" => 0,"f6" => 55,"f7" => 0,"f8" => 0,"f9" => 77,"f10" => 0,"f11" => 0,"f12" => 99,"f13" => 77,"f14" => 66,"f15" => 55,
"score" => 0
]
];
I need to get the sum of f1-f15. here is my code:
echo array_sum(array_map(function ($val){
return $val['f1']+$val['f2']+$val['f3']+$val['f4']+$val['f5']+$val['f6']+$val['f7']+$val['f8']+$val['f9']+$val['f10']+$val['f11']+$val['f12']+$val['f13']+$val['f14']+$val['f15'];
},$data));
It doesn't look too good, is there a better way to implement it? thanks!