public static function getSizeLength($size)
{
$str = '';
$units = ['m','km'];//单位字符,可类推添加更多字符.
if (!empty($size) && is_numeric($size)) {
foreach($units as $i => $unit){
if($i > 0){
$n = $size /pow(1000,$i)%pow(1000,$i);
}else{
$n = $size%1000;
}
if($n != 0){
$str = $n.$unit;
}
}
}
return $str;
}
{
$str = '';
$units = ['m','km'];//单位字符,可类推添加更多字符.
if (!empty($size) && is_numeric($size)) {
foreach($units as $i => $unit){
if($i > 0){
$n = $size /pow(1000,$i)%pow(1000,$i);
}else{
$n = $size%1000;
}
if($n != 0){
$str = $n.$unit;
}
}
}
return $str;
}