实例
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/4/19 0019 * Time: 上午 10:27 */ header("content-type:text/html;charset=utf-8"); /** * 数组排序 */ $arr = array(1, 2, 3, 4, 0, -1); /** * 依据值排序 */ $arr = array(1, 2, 3, 4, 0, -1); asort($arr, SORT_REGULAR);// 由低到高 索引不变 echo "<pre>"; print_r($arr); echo "</pre>"; echo "asort<hr>"; $arr = array(1, 2, 3, 4, 0, -1); arsort($arr, SORT_REGULAR);// 由高到低 索引不变 echo "<pre>"; print_r($arr); echo "</pre>"; echo "arsort<hr>"; $arr = array(1, 2, 3, 4, 0, -1); sort($arr, SORT_REGULAR);//由高到低 此函数为 array 中的元素赋与新的键名。这将删除原有的键名,而不是仅仅将键名重新排序。 echo "<pre>"; print_r($arr); echo "</pre>"; echo "sort<hr>"; //ksort()// 由低到高 依据key排序的 //排序都是 根据 ascii码表 内部 顺序依次排序的 $arr = array("name" => "qq", "age" => 12, "sex" => "男", "身高" => 175, "存款" => "100w"); ksort($arr); echo "<pre>"; print_r($arr); echo "</pre>"; echo "ksort<hr>"; //krsort()//索引保持由高到低 依据key排序的 //排序都是 根据 ascii码表 内部 顺序依次排序的 $arr = array("name" => "qq", "age" => 12, "sex" => "男", "身高" => 175, "存款" => "100w"); krsort($arr); echo "<pre>"; print_r($arr); echo "</pre>"; echo "krsort<hr>"; echo "<br>"; echo "<br>"; echo "<br>"; /** * 数组转化为字符串 */ $str = implode(",",$arr); echo $str."<br>"; echo "implode <hr>"; /** * 字符串长度计算 */ $str = "sss,455,4782,4ojhhhh,ouyio,ytwiure,oioiioer,iuwieuriw,oweirwiherw,qqqqq"; $strlength = strlen($str); echo "str_length=" . $strlength; echo "strlen<hr>"; /** * 字符串转化数组 根据固定长度拆分数组 */ $strArray = str_split($str, 3); echo "<pre>"; print_r($strArray); echo "</pre>"; echo "str_split<hr>"; /** * 字符串根据固定字段拆分数组 */ $strArray = explode(",", $str); echo " <pre>"; print_r($strArray); echo "</pre> "; echo "explode <hr>"; /** * 字符串替换 */ $strReplace = str_replace("45","《-》",$str); echo $strReplace."<br>"; echo "str_replace<hr>"; $strReplace = str_ireplace("ss","《--》",$str); echo $strReplace."<br>"; echo "str_ireplace<hr>"; /** * 查询一个字符串位置 */ $strPos = strpos($str,"ouyio"); echo $strPos."<br>"; echo "str_ireplace<hr>";
运行实例 »
点击 "运行实例" 按钮查看在线实例