First, bubble sort
<?PHP$arr=Array(1,5,9,7,2,8,4,3,6);//control the bubbling rounds for($i= 1;$i<Count($arr);$i++) { //control how many times you need to compare, one number per round for($k= 0;$k<Count($arr)-$i;$k++){ if($arr[$k]>$arr[$k+1]){ $tmp=$arr[$k+1]; $arr[$k+1]=$arr[$k]; $arr[$k]=$tmp; } }}Print_r($arr);
Second, using PHP built-in functions to calculate the length of the string
<? php $str = "Hello,world" ; $count = 0 while (1 if (@ $str [ $count ]! = null $count ++; continue ; else { break ; }} echo $count ;
Three, reverse output string
<? PHP $str = "Hello,world"; if ($strecho 0; $bstr = ""; for ($i= (strlen($str$i$i --) { $bstr $str[$i ];} Echo $bstr;
Iv. encryption, decryption
<?PHP$str= "Hello,world";$key= "Www.cnblogs.com";$str=$str.$key;$chars= "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-=+";$rand=Rand(0,64);$ch=$chars[$rand];$mdKey=MD5($key.$ch);$mdKey=substr($mdKey,$rand%8$rand%8+7);$str=Base64_encode($str);$tmp= ' ';$i= 0;$j= 0;$k= 0; for($i= 0;$i<strlen($str);$i++) { $k=$k==strlen($mdKey) ? 0:$k; $j= ($rand+Strpos($chars,$str[$i])+Ord($mdKey[$k+ +])%64; $tmp.=$chars[$j];}Echo UrlEncode(Base64_encode($ch.$tmp));<?PHP$str= "Ywfsu3ftuzyycdjjdlpszdfurgm1vjbfdvprsm5udjn1bjatta%3d%3d";$key= "Www.cnblogs.com";$str=Base64_decode(UrlDecode($str));$chars= "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-=+";$ch=$str[0];$rand=Strpos($chars,$ch);$mdKey=MD5($key.$ch);$mdKey=substr($mdKey,$rand%8$rand%8+7);$str=substr($str, 1);$tmp= ' ';$i= 0;$j= 0;$k= 0; for($i= 0;$i<strlen($str);$i++) { $k=$k==strlen($mdKey) ? 0:$k; $j=Strpos($chars,$str[$i])-$rand-Ord($mdKey[$k++]); while($j<0)$j+=64; $tmp.=$chars[$j];}Echo Trim(Base64_decode($tmp),$key);
.....
Several commonly used algorithms for PHP collation