After thinking and thinking I don´t find a way on how to solve this problem. I have been thinking of a loop inside a loop but I always reach to no end.
Having multidimensional arrays like these:
0 => {'id' => (int) 1,
'meritos' => [
'id' => '39',
'Puntuacion' => '6'
],
'categorias' => [
'id' => '29',
'PuntuacionMax' => '15'
]
},
1 => {'id' => (int) 3,
'meritos' => [
'id' => '40',
'Puntuacion' => '7'
],
'categorias' => [
'id' => '30',
'PuntuacionMax' => '10'
]
},
2 => {'id' => (int) 4,
'meritos' => [
'id' => '41',
'Puntuacion' => '8'
],
'categorias' => [
'id' => '30',
'PuntuacionMax' => '10'
]
},
3 => {'id' => (int) 4,
'meritos' => [
'id' => '42',
'Puntuacion' => '8'
],
'categorias' => [
'id' => '29',
'PuntuacionMax' => '15'
]
},
etc...
I need to sum all 'meritos' => 'Puntuacion' but with the following inconvenience:
The sum of 'meritos' => 'Puntuacion'
with the same 'categorias' => 'id'
can´t be superior to 'categorias' => 'PuntuacionMax'
I.E. with the arrays I gave.
I have two 'puntuacion' values that belongs to the same 'categorias' => 'id' (29)
which are 8 and 6.
The sum would be 14 and doesn´t surpass the puntuacionMax (15) so it´s ok.
The other two 'puntuacion' values that belongs to the same 'categorias' => 'id' (30) are 7 and 8. The sum would be 15 but surpass the puntuacionMax (10) so the result must be 10.
The final sum value would be 24 (sum from 14 and 10)
Thanks in advance for any help.