<?php
$arr = [4,9,8,6,7,3,2,1];
function bubbling($str){
$c = count($str);
for ($i=0; $i < $c; $i++) {
# code...
for ($j=$i; $j < $c; $j++) {
# code...
if ($str[$j]>$str[$j+1]) {
# code...
$temp = $str[$j];
$str[$j] = $str[$j+1];
$str[$j+1]=$temp;
}
}
}
return $str;
}
print_r(bubbling($arr));
?>