I have an mysql table named example.
 Id   | Amount  | Left | Filled
 1    |  1      |  1   | 0
 2    |  4      |  4   | 0
 5    |  7      |  7   | 0
I have an variable named $var = 9
Now I have an array named $array with those ids as array([0] => 1, [1] => 2, [2] => 5) Which itself is a mysql result.
How do I make a loop so that ids in array keep subtracting the left and keep filling as per the amount but within the total value of $var so that my end result in table is
 Id   | Amount  | Left | Filled
 1    |  1      |  0   | 1
 2    |  4      |  0   | 4
 5    |  7      |  3   | 4