In PHP, you can use the sort () function to sort the array elements.
Cases:
<?php
$arr =array (75,32,65,98,85,12);
Sort ($arr);
foreach ($arr as $k => $var) {
echo $var. " ";
}
?>
You can also sort the array elements using classic algorithms like bubble sort, quick sort, and the following are examples of bubble ordering:
Bubble sort
PHP File:
<?php
With bubble sort method, the small to large arrangement
$arr =array (75,32,65,98,85,12);
$temp = 0;
Why is Count ($arr)-1? For example, 3 digits, the location of the two number of digits, the 3rd nature is determined.
For ($i =0 $i <count ($arr)-1; $i + +) {
For ($j =0 $j <count ($arr)-$i; $j + +) {
if ($arr [$j]> $arr [$j +1]) {
$temp = $arr [$j];
$arr [$j]= $arr [$j +1];
$arr [$j +1]= $temp;
}
}
}
foreach ($arr as $k => $var) {
echo $var. " ";
}
?>
The results of the operation are shown below: