Advertisement
Virajsinh

Php division with no decimal separate result

Jun 22nd, 2023 (edited)
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.41 KB | Source Code | 0 0
  1. <?php
  2. // Sourse : https://stackoverflow.com/questions/47832429/php-division-with-no-decimal-separate-result
  3. $numbertodivise = 500;
  4. $no = 3;
  5.  
  6. $intnumber = intval($numbertodivise / $no);
  7. $rem = $numbertodivise % $no;
  8. $array = [];
  9.  
  10. for($i=1;$i<=$no;$i++) {
  11.     if($i==$no) {
  12.         $array[] = $intnumber + $rem;
  13.     } else {
  14.         $array[] = $intnumber;
  15.     }
  16. }
  17.  
  18. echo "<pre>";
  19. print_r($array);
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement