Hi,
I have a bunch of inputs to put in db
input[0]
input[1]
input[2]
etc...
they all carry integer values and their value sum must be equal to 100
for example
input[0] = 20
input[1] = 40
input[2] = 40
When I submit, I easily do the sum verification and make sure it is 100.
Now, those values are not mandatory, but I must insert something in database.
(if one input is filled all must be filled. Or all must be empty)
If they have 4 empty inputs I do 100/sizeof($array) and I get 25 each and it's perfect
But if it's not divisible, example 3 inputs at 100/3 will give me 33 for each and a total of 99
So how can I do for all empty: make division floor(100/total of inputs) and if the total of all is not equal to 100, adjust the last one to make it so.
e.g in example above the last 33 will become 34
and I put all those new values back in an array with their same keys
thank you.