Ò»¡¢Ã°ÅÝÅÅÐo
»u±¾Ë¼Ïe£º
¶ÔÐeÒªÅÅÐoµÄÊý×e´ÓºoÍuÇ°£¨ÄaeÐo£(C)½øÐжa±eµÄɨÃe£¬µ±*¢ÏÖÏaÁÚµÄÁ½¸oÊýÖµµÄ´ÎÐoÓeÅÅÐoÒªÇoµÄ¹aeÔo²»Ò»ÖÂʱ£¬¾Í½«ÕaÁ½¸oÊýÖµ½øÐн»»»¡£ÕaÑu±È½ÏС£¨´o£(C)µÄÊýÖµ¾Í½«Öð½¥´ÓºoÃaeÏoÇ°ÃaeÒƶ¯¡£
//ðÅÝÅÅÐo
<?php
function mysort($arr)
{
for($i = 0; $i < count($arr); $i++)
{
$isSort = false;
for ($j=0; $j< count($arr) - $i - 1; $j++)
{
if($arr[$j] < $arr[$j+1])
{
$isSort = true;
$temp = $arr[$j];
$arr[$j] = $arr[$j+1];
$arr[$j+1] = $temp ;
}
}
if($isSort)
{
break;
}
}
return $arr;
}
$arr = array(3,1,2);
var_dump(mysort($arr));
?>
¶þ¡¢¿iËÙÅÅÐo
»u±¾Ë¼Ïe£º
ÔÚÊý×eÖÐÌo³oÒ»¸oÔªËØ£¨¶aΪµÚÒ»¸o£(C)×÷Ϊ±e³ß£¬É¨ÃeÒ»±eÊý×e½«±È±e³ßСµÄÔªËØÅÅÔÚ±e³ß֮ǰ£¬½«ËuÓбȱe³ß´oµÄÔªËØÅÅÔÚ±e³ßÖ®ºo£¬Í¨¹ýµÝ¹e½«¸÷×ÓÐoÁÐÖ±ð»®ÖΪ¸uСµÄÐoÁÐÖ±µ½ËuÓеÄÐoÁÐ˳ÐoÒ»Ö¡£
//¿iËÙÅÅÐo
<?php
//¿iËÙÅÅÐo
function quick_sort($arr)
{
//ÏÈÅжÏÊÇ*ñÐeÒª¼ÌÐø½øÐÐ
$length = count($arr);
if($length <= 1)
{
return $arr;
}
$base_num = $arr[0];//Ñ¡ÔñÒ»¸o±e³ß Ñ¡ÔñµÚÒ»¸oÔªËØ
//³oʼ»¯Á½¸oÊý×e
$left_array = array();//СÓÚ±e³ßµÄ
$right_array = array();//´oÓÚ±e³ßµÄ
for($i=1; $i<$length; $i++)
{ //±eÀu ³ýÁ˱e³ßÍaµÄËuÓÐÔªËØ£¬°´ÕÕ´oС¹Øϵ*ÅÈeÁ½¸oÊý×eÄÚ
if($base_num > $arr[$i])
{
//*ÅÈe×o±ßÊý×e
$left_array[] = $arr[$i];
}
else
{
//*ÅÈeÓÒ±ß
$right_array[] = $arr[$i];
}
}
//ÔÙ*Ö±ð¶Ô ×o±ß ºÍ ÓұߵÄÊý×e½øÐÐÏaͬµÄÅÅÐo´¦Ài*½Ê½
//µÝ¹eµ÷ÓÃÕa¸oº¯Êý,²¢¼Ç¼½a¹u
$left_array = quick_sort($left_array);
$right_array = quick_sort($right_array);
//ºÏ²¢×o±ß ±e³ß ÓÒ±ß
return array_merge($left_array, array($base_num), $right_array);
}
$arr = array(3,1,2);
var_dump(quick_sort($arr));
?>
*Èý¡¢¶þÖ²eÕÒ**
»u±¾Ë¼Ïe£º
¼ÙÉeÊý¾ÝÊÇ°´ÉýÐoÅÅÐoµÄ£¬¶ÔÓÚ¸ø¶¨Öµx£¬´ÓÐoÁеÄÖмaλÖÿªÊ¼±È½Ï£¬Èç¹uµ±Ç°Î»ÖÃÖµµÈÓÚx£¬Ôo²eÕҳɹ¦£»ÈoxСÓÚµ±Ç°Î»ÖÃÖµ£¬ÔoÔÚÊýÁеÄÇ°°e¶ÎÖвeÕÒ£»Èox´oÓÚµ±Ç°Î»ÖÃÖµÔoÔÚÊýÁеĺo°e¶ÎÖмÌÐø²eÕÒ£¬Ö±µ½ÕÒµ½ÎªÖ¹¡££¨Êý¾ÝÁ¿´oµÄʱºoʹÓã(C)
//¶þ*Ö²eÕÒ
<?php
//¶þ*Ö²eÕÒ
function bin_search($arr,$low,$high,$k)
{
if($low <= $high)
{
$mid = intval(($low + $high)/2);
if($arr[$mid] == $k)
{
return $mid;
}
else if($k < $arr[$mid])
{
return bin_search($arr,$low,$mid-1,$k);
}
else
{
return bin_search($arr,$mid+1,$high,$k);
}
}
return -1;
}
$arr = array(1,2,3,4,5,6,7,8,9,10);
print(bin_search($arr,0,9,3));
?>
ËÄ¡¢Ë³Ðo²eÕÒ
»u±¾Ë¼Ïe£º
´ÓÊý×eµÄµÚÒ»¸oÔªËØ¿ªÊ¼Ò»¸oÒ»¸oÏoϲeÕÒ£¬Èç¹uÓкÍÄ¿±eÒ»ÖµÄÔªËØ£¬²eÕҳɹ¦£»Èç¹uµ½×iºoÒ»¸oÔªËØÈÔûÓÐÄ¿±eÔªËØ£¬Ôo²eÕÒʧ°Ü¡£
//˳Ðo²eÕÒ¡¡
<?php
//˳Ðo²eÕÒ
function seq_search($arr,$n,$k)
{
$array[$n] = $k;
for($i = 0;$i < $n; $i++)
{
if($arr[$i] == $k)
{
break;
}
}
if($i < $n)
{
return $i;
}
else
{
return -1;
}
}
?>
Îa¡¢Ð´Ò»¸oº¯Êý£¬Äܹ»±eÀuÒ»¸oÎļþϵÄËuÓÐÎļþºÍ×ÓÎļþ¼Ð
<?php
function my_scandir($dir)
{
$files = array();
if($handle = opendir($dir))
{
while (($file = readdir($handle))!== false)
{
if($file != '..' && $file != '.')
{
if(is_dir($dir."/".$file))
{
$files[$file]=my_scandir($dir."/".$file);
}
else
{
$files[] = $file;
}
}
}
closedir($handle);
return $files;
}
}
var_dump(my_scandir('../'));
?>
Áu¡¢Ð´Ò»¸oº¯Êý£¬¾¡¿ÉÄܸßЧµÄ´ÓÒ»¸o±e×¼urlÖÐÈ¡³oÎļþµÄÀ(C)Õ¹Ãu
<?php
function getExt($url)
{
$arr = parse_url($url);//parse_url½aÎoÒ»¸o URL ²¢*µ»ØÒ»¸o¹ØÁªÊý×e£¬°uº¬ÔÚ URL ÖгoÏֵĸ÷ÖÖ×e³É²¿*Ö
//'scheme' => string 'http' (length=4)
//'host' => string 'www.sina.com.cn' (length=15)
//'path' => string '/abc/de/fg.php' (length=14)
//'query' => string 'id=1' (length=4)
$file = basename($arr['path']);// basenameº¯Êý*µ»ØÂ*¾¶ÖеÄÎļþÃu²¿*Ö
$ext = explode('.', $file);
return $ext[count($ext)-1];
}
print(getExt('http://www.sina.com.cn/abc/de/fg.html.php?id=1'));
?>
*Æß¡¢ÊµÏÖÖÐÎÄ×Öu´®½ØÈ¡ÎÞÂÒÂeµÄ½¨**
¿ÉʹÓÃmb_substr,µ«ÊÇÐeҪȱ£ÔÚphp.iniÖмÓÔØÁËphp_mbstring.dll£¬¼´È±£¡°extension=php_mbstring.dll¡±ÕaÒ»ÐдaeÔÚ²¢ÇÒûÓб»×¢Ê͵o£¬*ñÔo»a³oÏÖ䶨Òaº¯ ÊýµÄÎÊÌa¡£
ÒÔÉÏÕaƪPHPÃaeÊÔ³£ÓÃËa¨(ÍƼo)¾ÍÊÇС±aÖÏi¸ø´o¼ÒµÄÈ«²¿ÄÚÈÝÁË£¬Ï£ÍuÄܸø´o¼ÒÒ»¸o²Î¿¼£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£