CacheTool\Util\Formatter::bytes PHP Method

bytes() public static method

public static bytes ( integer $bytes, integer $precision = 2 ) : string
$bytes integer
$precision integer
return string
    public static function bytes($bytes, $precision = 2)
    {
        $units = array('b', 'KiB', 'MiB', 'GiB', 'TiB');
        $bytes = max($bytes, 0);
        $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
        $pow = min($pow, count($units) - 1);
        $bytes /= 1 << 10 * $pow;
        return round($bytes, $precision) . ' ' . $units[$pow];
    }

Usage Example

 protected function processFileList(array $cacheList)
 {
     $list = array();
     foreach ($cacheList as $item) {
         $list[] = array(number_format($item['num_hits']), $item['access_time'] > 0 ? 'Yes' : 'No', $item['deletion_time'] > 0 ? 'Yes' : 'No', Formatter::bytes($item['mem_size']), $this->processFilename($item['filename']));
     }
     return $list;
 }
All Usage Examples Of CacheTool\Util\Formatter::bytes
Formatter