php bubble sort exchange sort

  • 2020-05-05 11:01:11
  • OfStack

 
$a=array('11','2','13','4','22'); 
$num = count($a); 
for($i=0;$i<$num;$i++){ 
for($j=0;$j<$num;$j++){ 
if($a[$i]<$a[$j]){ 
$temp = $a[$i]; 
$a[$i]=$a[$j]; 
$a[$j]=$temp; 
} 
} 
} 
print_r($a); 

Related articles: