CodesJava

Easy learning with example program codes

PHP program to sort elements of an array in ascending order

PHP program to sort elements of an array in ascending order:

The below program is to sort elements of an array in ascending order using PHP sort() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time.

Example

<!DOCTYPE html>
<html>
<body>
 
<?php    
$numbers=array("100","160","20","67");    
sort($numbers);  
foreach( $numbers as $n )    
{    
  echo "$n<br />";    
}    
?>	
 
</body>
</html>

Output

20
67
100
160
Please follow and like us:
error
Posted in PHP   








Copyright © 2019 CodesJava DMCA.com Protection Status