Wednesday 13 September 2017

How to get closest date compared to an array of dates in PHP

Here Explain about how to find nearest date from any array of dates
Let's say I have an array as follows:

Array
(
    [0] => 2017-09-14
    [1] => 2017-09-15
    [2] => 2017-09-16
    [3] => 2017-09-17
    [4] => 2017-09-18
    [5] => 2017-09-19
)

Thursday 24 August 2017

File Size MB/KB/GB Conversion

The File size conversion as per The size is less than 1 MB, show the size in KB, if it's between 1 MB - 1 GB show it in MB, if it's larger - in GB
<?php
    function fileSizeConversion($bytes)
    {
        if ($bytes >= 1073741824)
        {
            $bytes = number_format($bytes / 1073741824, 2) . ' GB';
        }
        elseif ($bytes >= 1048576)
        {
            $bytes = number_format($bytes / 1048576, 2) . ' MB';
        }
        elseif ($bytes >= 1024)
        {
            $bytes = number_format($bytes / 1024, 2) . ' KB';
        }
        elseif ($bytes > 1)
        {
            $bytes = $bytes . ' bytes';
        }
        elseif ($bytes == 1)
        {
            $bytes = $bytes . ' byte';
        }
        else
        {
            $bytes = '0 bytes';
        }

        return $bytes;
    }

?>