PHP冒泡排序
麻烦高手给个PHP的冒泡排序,本人刚刚开始学PHP,自己写了一个,总是不成功。。。
PHP code:
<?php
function paixu($str)
{
$n=count($str);
for ($i=0;$i<$n;$i++)
{
for ($j=$n-2;$j>=$i;$j--)
{
if($str[$j+1]<$str[$j])
{
$tmp = $str[$j+1];
$str[$j+1]=$str[$j];
$str[$j]=$tmp;
}
}
}
$str=implode(",",$str);
return $str;
}
$str = array(3,6,1,5,9,0,4,6,11);
print_r(paixu($str));
?>
和用java写的差不多吧
没有什么区别
支持ls的
这样写有什么不对吗? 怎么结果不对啊 ??
<?php
function paixu($arr){
for($i=0;$i <=count($arr);$i++)
{
for($j=1;$j <=count($arr)-$i-1;$j++)
{
if($arr[$j+1] <$arr[$j])
{
$temp=$arr[$j+1];
$arr[$j+1]=$arrr[$j];
$arr[$j]=$temp;
}
}
}
$arr=implode(".",$arr);
return $arr;
}
$arr=array(2,5,4,1,7,6,8);
print_r(paixu($
相关问答:
如题,请知道的高手指点一下,THANKS
PHP函数都是用C实现的~
反其道而行之~
HOHO,关键是,自已再去实现这个功能累啊,PHP有现成的就直接调用好了,
顶起,有高手点解一下,或者是我直接将PHP 源码中的 .c ......
<?php
if($_SERVER['HTTP_REFERER']!=''){
@header("Content-type:image/jpeg");
echo file_get_contents("xlight.jpg");
}
else{
@header("location:ht ......
$a = $_FILES['userfile']['name'] ;
$test = $a;
$p = split('/',$test);
$p[count($p)-1];
$content = file_get_contents("$p");
$con ......
<?php
/*
功能:PHP伪静态化页面的实现
具体用法:
例如链接为:test.php/year/2006/action/_add.html
mod_rewrite();
$yearn= $_GET["year"];//结果为'2006'
......