php 简单的 冒泡排序

<?php 
$data = array('1','34','21','45','63','22');
//sort($data);
//print_r($data);die;
$count = count($data);
for($i=1;$i<$count;$i++)
{
   for($j=0;$j< $count-$i ;$j++)
   {
      if($data[$j]<$data[$j+1])
      {
       $str = $data[$j+1];
       $data[$j+1]=$data[$j];
       $data[$j]=$str;
      }
   }
}
print_r($data);
?>

 

posted @ 2017-03-23 16:56  施公子的二十七杯酒  阅读(146)  评论(0编辑  收藏  举报