Skip to content

Instantly share code, notes, and snippets.

@hamzaali00001
Created August 25, 2018 11:32
Show Gist options
  • Save hamzaali00001/4117c69a9eef89db15c0581a1c676a80 to your computer and use it in GitHub Desktop.
Save hamzaali00001/4117c69a9eef89db15c0581a1c676a80 to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('human_file_size')) {
/**
* Returns a human readable file size
*
* @param integer $bytes
* Bytes contains the size of the bytes to convert
*
* @param integer $decimals
* Number of decimal places to be returned
*
* @return string a string in human readable format
*
* */
function human_file_size($bytes, $decimals = 2)
{
$sz = 'BKMGTPE';
$factor = (int)floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sz[$factor];
}
}
if (!function_exists('in_arrayi')) {
/**
* Checks if a value exists in an array in a case-insensitive manner
*
* @param mixed $needle
* The searched value
*
* @param $haystack
* The array
*
* @param bool $strict [optional]
* If set to true type of needle will also be matched
*
* @return bool true if needle is found in the array,
* false otherwise
*/
function in_arrayi($needle, $haystack, $strict = false)
{
return in_array(strtolower($needle), array_map('strtolower', $haystack), $strict);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment