I have a multidimensional array with a maximum depth of 4 levels, but not all columns exist in the lower levels and some columns contain subsets instead of primitive values.
I need to calculate the sum of column values.
I wish to get the sum total of [price], [adults] and [children] but have not been able traverse the levels.
The answer I should get with this example is price=380 adults=5 and children=1.
Here is my input array:
[
8 => [
2 => [
'num_rooms' => 2,
'adults' => [1, 1],
'children' => [0, 0],
'prices' => [50, 50],
'price' => 130,
'supp' => 30,
],
3 => [
'num_rooms' => 1,
'adults' => [1],
'prices' => [100],
'price' => 150,
'supp' => 50,
],
],
1 => [
2 => [
'num_rooms' => 2,
'adults' => [1, 1],
'children' => [1, 0],
'prices' => [75, 75],
'price' => 170,
'supp' => 20,
],
],
]
pricesvalues is350. Summing thepricevalues is450. Your desired result is380.