note 123967 added to function.disk-free-space

From: Date: Thu, 20 Jun 2019 11:58:55 +0000
Subject: note 123967 added to function.disk-free-space
Groups: php.notes 
Request: Send a blank email to php-notes+get-211321@lists.php.net to get a copy of this message
<?php function size($size, array $options=null) { $o = [ 'binary' => false, 'decimalPlaces' => 2, 'decimalSeparator' => '.', 'thausandsSeparator' => '', 'maxThreshold' => false, // or thresholds key 'sufix' => [ 'thresholds' => ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'], 'decimal' => ' {threshold}B', 'binary' => ' {threshold}iB' ] ]; if ($options !== null) $o = array_replace_recursive($o, $options); $count = count($o['sufix']['thresholds']); $pow = $o['binary'] ? 1024 : 1000; for ($i = 0; $i < $count; $i++) if (($size < pow($pow, $i + 1)) || ($i === $o['maxThreshold']) || ($i === ($count - 1)) ) return number_format( $size / pow($pow, $i), $o['decimalPlaces'], $o['decimalSeparator'], $o['thausandsSeparator'] ) . str_replace( '{threshold}', $o['sufix']['thresholds'][$i], $o['sufix'][$o['binary'] ? 'binary' : 'decimal'] ); } var_dump(size(disk_free_space('/'))); // string(8) "14.63 GB" var_dump(size(disk_free_space('/'), ['binary' => true])); // string(9) "13.63 GiB" var_dump(size(disk_free_space('/'), ['maxThreshold' => 2])); // string(11) "14631.90 MB" var_dump(size(disk_free_space('/'), ['binary' => true, 'maxThreshold' => 2])); // string(12) "13954.07 MiB" ?> ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.195 (proxied: 77.238.70.70) ---- Manual Page -- http://php.net/manual/en/function.disk-free-space.php Edit -- https://master.php.net/note/edit/123967 Del: integrated -- https://master.php.net/note/delete/123967/integrated Del: useless -- https://master.php.net/note/delete/123967/useless Del: bad code -- https://master.php.net/note/delete/123967/bad+code Del: spam -- https://master.php.net/note/delete/123967/spam Del: non-english -- https://master.php.net/note/delete/123967/non-english Del: in docs -- https://master.php.net/note/delete/123967/in+docs Del: other reasons-- https://master.php.net/note/delete/123967 Reject -- https://master.php.net/note/reject/123967 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#211321) next »