3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$amount = number_format(9.22337203685E+18,0,'',''); $amount = 223372036849999872; $number_sep = array(); $multi = 1; $exit = false; $i = 1000; for($j=3;$j < 15 ;$j=$j+2) { switch($j) { case 3: $temp = ($amount/$i);echo $temp;$temp = round(($temp - floor($temp)) * 1000,2); if($i < $amount) { if(!$temp) { $number_sep[] = '000'; } else { $amount = $amount - $temp; $number_sep[] = str_pad(round($temp,2),3,'0',STR_PAD_LEFT); } } else { if(!$temp) { $number_sep[] = '000'; } else { $number_sep[] = str_pad(round($temp,2),3,'0',STR_PAD_LEFT); } $exit = true; } break; case $j > 3 : $temp = $amount % $i; if($i < $amount) { if(!$temp) { $number_sep[] = '00'; } else { $amount = $amount - $temp; echo $temp; $number_sep[] = round($temp/($i/100),0); } } else { if(!$temp) { $number_sep[] = '00'; } else { $number_sep[] = round($temp/($i/100),0); } $exit = true; }; break; } print_r($number_sep); if($exit) { break; } $i = 10 * 10 * $i; } echo implode(',',array_reverse($number_sep));
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.1, 5.2.7 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
2.2337203685E+14Array ( [0] => 875 ) 99008Array ( [0] => 875 [1] => 99 ) 9900000Array ( [0] => 875 [1] => 99 [2] => 99 ) 840000000Array ( [0] => 875 [1] => 99 [2] => 99 [3] => 84 ) 36000000000Array ( [0] => 875 [1] => 99 [2] => 99 [3] => 84 [4] => 36 ) 2000000000000Array ( [0] => 875 [1] => 99 [2] => 99 [3] => 84 [4] => 36 [5] => 20 ) 20,36,84,99,99,875
Output for 5.2.2 - 5.2.6
223372036850000Array ( [0] => 875 ) 99008Array ( [0] => 875 [1] => 99 ) 9900000Array ( [0] => 875 [1] => 99 [2] => 99 ) 840000000Array ( [0] => 875 [1] => 99 [2] => 99 [3] => 84 ) 36000000000Array ( [0] => 875 [1] => 99 [2] => 99 [3] => 84 [4] => 36 ) 2000000000000Array ( [0] => 875 [1] => 99 [2] => 99 [3] => 84 [4] => 36 [5] => 20 ) 20,36,84,99,99,875

preferences:
274.65 ms | 406 KiB | 314 Q