PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 9: Write a PHP program to sort an array.


<!DOCTYPE html>
	<title>PHP Programs</title>
		$numbers = array(10,15,12,14,17);
		$array_size = count($numbers);

		echo "Numbers before sort:  ";
		for ($i=0; $i < $array_size ; $i++)
		echo $numbers[$i]," ";
		echo "<br>";
		for ($i=0; $i <$array_size ; $i++) 
			for ($j=0; $j <$array_size ; $j++)
				if($numbers[$i] < $numbers[$j])
					$temp = $numbers[$i];
					$numbers[$i] = $numbers[$j];
					$numbers[$j] = $temp;

		echo"Numbers after sort:  ";
		for($i=0; $i<$array_size; $i++)

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.