Here’s a snippet in sorting using bubble sort algorithm in PHP
<?php
$num = array(10, 1, 3, 4, 9, 7, 2, 5, 8);
var_dump($num);
for($j=1;$j<count($num);$j++)
{
$key=$num[$j];
$i=$j-1;
while($num[$i]=0)
{
$num[$i+1]=$num[$i];
$i--;
}
$num[$i+1]=$key;
}
var_dump($num);
$num
is the array of integers to be sorted. When sorting done, $num
will contain sorted integers in descending order.