Function to format bytes in human readable format

I was digging through my old codes to get this, still could not find. Hence when I wrote it, just made a note here such that later it wont be difficult to find atleast for me.

function formatSize($size){
     
$units = array(' B'' KB'' MB'' GB'' TB');
     for (
$i 0$size 1024$i++) { $size /= 1024; }
     return 
round($size2).$units[$i];
 }

format filesize, php filesize human readable