PHP Program to Display Array Elements in Descending Order of an Array

PHP Program to Display Array Elements in Descending Order of an Array

  • PHP
  • 1 min read

Here is a PHP program to display the array elements in descending order of an array.

<html>
<body>
<?php
$a=array(10,90,70,120,200,6);
$b=count($a);
for($i=0;$i<$b-1;$i=$i+1)
{
for($j=$i+1;$j<$b;$j=$j+1)
{
if($a[$i]<$a[$j])
{
$temp=$a[$i];
$a[$i]=$a[$j];
$a[$j]=$temp;
}
}
}
echo "The array elements are:-"."<br>";
for($i=0;$i<$b;$i=$i+1)
{
echo $a[$i]."<br>";
}
?>
</body>
</html>

Output: The array elements are:-

200
100
120
90
10
6

See also: