Created
July 17, 2015 13:38
-
-
Save kirilkirkov/0444d3fd95ef30facac3 to your computer and use it in GitHub Desktop.
Return a size in bytes,kilobytes,megabytes and gigabytes for given array or string. Can be used if you want to check performance for some script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function array_size($arr) { | |
$byte = 0; | |
foreach ($arr as $key => $val) { | |
$byte += is_array($val) ? array_size($val) : mb_strlen($val); | |
} | |
$kb = number_format($byte / 1024, 4); | |
$mb = number_format($byte / 1048576, 4); | |
$gb = number_format($byte / 1073741824, 4); | |
$result = array('Bytes: ' => $byte, 'Kilobytes: ' => $kb, 'Megabytes: ' => $mb, 'Gigabytes: ' => $gb); | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment