PHP Round Up to nearest Array

//array list
$array = array(1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 150, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000);

//array round up function
function getArrayRoundUp($array, $number) {

foreach ($array as $a) {
if ($a >= $number) return $a;
return end($array);

//assume this is the value
$value = 904.5;

$nearest = getArrayRoundUp($array, $value);

//the expect result will be 1000
echo $nearest;


php rename file extension

When come to Linux it is case sensitive. How do you set all your file extension in the same case.

Below is the code how I rename the file extension all from .JPG (does not matter what is the original) to .jpg


function replace_extension($filename, $new_extension) {
     $info = pathinfo($filename);

    $newname = $info['filename'] . '.' . $new_extension;
    rename('/home/image/'.$filename, '/home/image/'.$newname);
    return $newname;


$dir = '/home/image';
$files = scandir($dir);


foreach($files as $key => $file)
     echo replace_extension($file, 'jpg');
    echo "<br />";




Install PHPUnit in Windows

How to install PHPUnit in Windows


1. PHP installed. PHPUnit 4.1 requires PHP 5.3.3; using the latest version of PHP is highly recommended.

2. Set your PHP folder (e.g C:phpbin) to your Environment Variable. Thus, you can run php in your command prompt without full path


Step to install PHPUnit

1. Download from the PHPunit website., if you PC support wget you can use the following command to download the phpunit.phar to your php bin folder.


My case it will located in C:phpbinphpunit.phar

2. Create a .bat file, you can create a .txt file rename it to .bat later. Inside the content paste these in

@echo off
php "%~dp0phpunit.phar" %*

Rename your txt file to .bat


Access to your Command prompt, try enter the command phpunit, you should able to see the below result:

Enjoy your testing!

PS: No color in your testing output in command prompt? Read the next post to enable it!