fork download
  1. <?php
  2.  
  3. $numbers = [21.3333, 65.3333, 13.3333];
  4.  
  5. $roundeds = array_map("round", array_slice($numbers, 0, -1));
  6. $roundeds[] = (int) 100 - array_sum($roundeds);
  7.  
  8. print_r($roundeds);
  9.  
  10. $numbers = [50.4, 50.6];
  11.  
  12. $roundeds = array_map("round", array_slice($numbers, 0, -1));
  13. $roundeds[] = (int) 100 - array_sum($roundeds);
  14.  
  15. print_r($roundeds);
  16.  
  17.  
  18. $numbers = [0.1, 0.1];
  19.  
  20. $roundeds = array_map("round", array_slice($numbers, 0, -1));
  21. $roundeds[] = (int) 100 - array_sum($roundeds);
  22.  
  23. print_r($roundeds);
Success #stdin #stdout 0.02s 23800KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 21
    [1] => 65
    [2] => 14
)
Array
(
    [0] => 50
    [1] => 50
)
Array
(
    [0] => 0
    [1] => 100
)