i've a multidimensional array like this one:
['2021-04-01'=>
['hb' => 35, 'fb' => 40, 'ai' => 50],
'2021-04-02'=>
['hb' => 35, 'fb' => 40, 'ai' => 50],
'2021-04-03'=>
['hb' => 40, 'ai' => 55],
'2021-04-04'=>
['hb' => 40, 'fb' => 45, 'ai' => 55],
'2021-04-05'=>
['hb' => 35, 'ai' => 50]]
I'd like to receive an array like this one:
['hb'=>185,'ai'=>260]
Basically i've to sum the price of every single treatment (hb=half-board, fb=full board, ai=all inclusive) only if the treatment is present in every element of the array.
Short solution with array_reduce().
$arr is your input-array, $sum the result.
More understandable what array_reduce makes is a simple loop with foreach.