天天看点

冒泡求和排序do while

<?php

 $sum=0;

 $sum1=0;

 $sum2=0;

 for($i=1;$i<=100;$i++)

 {

  $sum+=$i;

  $sum1+=++$i;  //偶数和

  $sum=$i+$sum;

  $sum2=$sum-$sum1;

 }

   echo$sum.'<br>';

   echo$sum1.'<br>';

        echo $sum2.'<br>';

// 九九口诀

  for($i=1;$i<=9;++$i)

    { echo '<table;

           echo'<tr>';

     for($j=1;$j<=$i;++$j)

    {

   echo '<td>';

    echo $j*$i;

     echo'</td>';

    }

 echo'</tr>';

echo'</table>';

}

//加法

  for($i=0;$i<=9;$i++)

  {   echo'<table ;

//           echo'<tr>';

  for($j=0;$j<=$i;$j++)

   {  echo '<td>';

  echo$i+$j.'<br>';

  echo'</td>';

 }   echo'</tr>';

     echo'</table>';

//    echo$i*$j.'<br>';

 }

//  DO while 语句的书写

  $i=3;

 do{

  $i++;

  echo $i;

 }

 while($i<10)

 $str='dshkfj dfhdskj';

  $str=explode(' ',$str) ;

  print_r($str);

  $s=$str[0];

  $b=$str[1];

  echo $b;

//  年月日

 function get_date($data)

 {

   $str= explode('/',$data);

   $year = $str['0'];

   $month =$str['1'];

   if(in_array($month,array(1,3,5,7,8,10,12)))

  {

  echo$year.'年的'.$month.'月有31天';

  }

  elseif($month==2){

  if([email protected]==0 || ($year%4==0&& $year0 !==0))

   {

   echo$year.'年的'.$month.'月有29天';

  }

   else{

    echo$year.'年的'.$month.'月有28天';

   }

 }

  else{

  echo $year.'年的'.$month.'月有30天';}

 }

 echo get_date('2012/3') ;

//  冒泡排序法

  $arr=array(1,3,7,5,9,0);

   function maopao($arr)

   {

   $N=count($array);

  for($i=$N;$i>0;$i--)

    {

   for( $j = 0 ;$j< $i-1 ; $j++)

        {

         if($array[$i]>$array[$i+1])

         {

         $M=$array[$i];

         $array[$i+1]=$array[$i];

         $array[$i+1]=$M;

         }

        }

    }

    return$array;

   $str=maopao($arr);

   print_r($str);

   }

  //函数排序

  $arr=array(1,70,7,9);

    $array=sort($arr);

 for($i=0;$i<count($arr);$i++){

  echo$arr[$i].'&nbsp';

  }

// shuffle 随机对内容进行排序

 $array=array("你","们","去","做","什","么","呀","?");

  shuffle($array);

 for($i=0;$i<count($array);$i++){

   echo$array[$i]."&nbsp";

  }

// 

  对数组中的数字进行求和

   $array=range(1,100,1);

   $SUM=array_sum($array);

   echo $SUM.'从一到一百的和';