<?php function convert($i){ $rules = array("KB"=>1000, "MB"=>1000000, "GB"=>1000000000,"TB"=>1000000000000); $reversedRules= array_reverse($rules); foreach($reversedRules as $k=>$r){ if(($output = $i/$r) >= 1){ return round($output).$k; } } return $i."B"; } echo convert(21312312312312321); echo convert(1000); echo convert(1232); echo convert(9999999); echo convert(12); echo convert(231671851); echo convert(321784535432);
You have javascript disabled. You will not be able to edit any code.