/** byte字节单位转换函数
* @param int $byte
* @return string
*/
function byte(int $byte){
$suffixes=["YB","ZB","EB","PB","TB","GB","MB","KB"];
do{
$byte=round($byte/1024,2);
$suffix=array_pop($suffixes);
}while($byte>=1024&&!empty($suffixes));//$suffixes 为空则单位用尽,不再计算
return $byte . $suffix;
}
$byte=1024*1024*13;
$res=byte($byte);
var_dump($res);
string(5) "13MB"