php 功能函数集
1.獲取頁面閉合帶id標簽數據
View Code 1 <?php 2 header("Content-type: text/html; charset=utf-8"); 3 /** 4 * $tag_id HTML tag_id like id="abc" 5 * $url web url 6 * $tag HTML tag 7 * $data HTML data if $url set to false 8 * @example echo getWebTag('id="nav"','http://mail.163.com/html/mail_intro/','ul'); 9 */ 10 function getWebTag($tag_id,$url=false,$tag='div',$data=false){ 11 if($url !== false){ 12 $data = file_get_contents( $url ); 13 } 14 $charset_pos = stripos($data,'charset'); 15 if($charset_pos) { 16 if(stripos($data,'utf-8',$charset_pos)) { 17 $data = iconv('utf-8','utf-8',$data); 18 }else if(stripos($data,'gb2312',$charset_pos)) { 19 $data = iconv('gb2312','utf-8',$data); 20 }else if(stripos($data,'gbk',$charset_pos)) { 21 $data = iconv('gbk','utf-8',$data); 22 } 23 } 24 25 preg_match_all('/<'.$tag.'/i',$data,$pre_matches,PREG_OFFSET_CAPTURE); //獲取所有div前綴 26 preg_match_all('/<\/'.$tag.'/i',$data,$suf_matches,PREG_OFFSET_CAPTURE); //獲取所有div后綴 27 $hit = strpos($data,$tag_id); 28 if($hit == -1) return false; //未命中 29 $divs = array(); //合并所有div 30 foreach($pre_matches[0] as $index=>$pre_div){ 31 $divs[(int)$pre_div[1]] = 'p'; 32 $divs[(int)$suf_matches[0][$index][1]] = 's'; 33 } 34 35 //對div進行排序 36 $sort = array_keys($divs); 37 asort($sort); 38 39 $count = count($pre_matches[0]); 40 foreach($pre_matches[0] as $index=>$pre_div){ 41 //<div $hit <div+1 時div被命中 42 if(($pre_matches[0][$index][1] < $hit) && ($hit < $pre_matches[0][$index+1][1])){ 43 $deeper = 0; 44 //彈出被命中div前的div 45 while(array_shift($sort) != $pre_matches[0][$index][1] && ($count--)) continue; 46 //對剩余div進行匹配,若下一個為前綴,則向下一層,$deeper加1, 47 //否則后退一層,$deeper減1,$deeper為0則命中匹配,計算div長度 48 foreach($sort as $key){ 49 if($divs[$key] == 'p') $deeper++; 50 else if($deeper == 0) { 51 $length = $key-$pre_matches[0][$index][1]; 52 break; 53 }else { 54 $deeper--; 55 } 56 } 57 $hitDivString = substr($data,$pre_matches[0][$index][1],$length).'</'.$tag.'>'; 58 break; 59 } 60 } 61 return $hitDivString; 62 } 63 64 echo getWebTag('id="nav"','http://mail.163.com/html/mail_intro/','ul'); 65 echo getWebTag('id="homeBanners"','http://mail.163.com/html/mail_intro/'); 66 echo getWebTag('id="performance"','http://mail.163.com/html/mail_intro/','section'); 67 68 //End_php1.1 由(1)改進為獲取頁面任意標簽,參考《顛覆想象的php解析獲取跨域HTML標簽》
View Code 1 <?php 2 header("Content-type: text/html; charset=utf-8"); 3 /** 4 * $tag_id HTML tag_id like id="abc" 5 * $url web url 6 * $tag HTML tag 7 * $data HTML data if $url set to false 8 * $first Only get the first match 9 * @example 10 var_dump(getWebTag('id="nav"','http://mail.163.com/html/mail_intro/','ul')); 11 */ 12 function getWebTag($tag_id,$url=false,$tag='div',$data=false,$first=false){ 13 //默認采用URL獲取數據 14 if($url !== false){ 15 $data = file_get_contents( $url ); 16 } 17 //頁面編碼判定及轉碼 18 $charset_pos = stripos($data,'charset'); 19 if($charset_pos) { 20 if(stripos($data,'charset=utf-8',$charset_pos)) { 21 $data = iconv('utf-8','utf-8',$data); 22 }else if(stripos($data,'charset=gb2312',$charset_pos)) { 23 $data = iconv('gb2312','utf-8',$data); 24 }else if(stripos($data,'charset=gbk',$charset_pos)) { 25 $data = iconv('gbk','utf-8',$data); 26 } 27 } 28 29 //匹配命中標簽至數組$hits 30 preg_match_all('/<'.$tag.'[^<]*?'.$tag_id.'/i',$data,$hits,PREG_OFFSET_CAPTURE); 31 if(count($hits[0]) === 0) { //未命中,直接返回 32 return '沒有匹配項!'; 33 } 34 35 preg_match_all('/<'.$tag.'/i',$data,$pre_matches,PREG_OFFSET_CAPTURE); //獲取所有HTML標簽前綴 36 preg_match_all('/<\/'.$tag.'/i',$data,$suf_matches,PREG_OFFSET_CAPTURE); //獲取所有HTML標簽后綴 37 38 //判斷是否<div></div>格式,是則添加結束標簽,否則為false; 注:img、input等可能不是這種格式,此時$suf_matches[0]為空。 39 if(!empty($suf_matches[0])) $endTag = '</'.$tag.'>'; 40 else $endTag = false; 41 42 //合并所有HTML標簽 43 $htmltags = array(); 44 if($endTag !== false){ 45 foreach($pre_matches[0] as $index=>$pre_div){ 46 $htmltags[(int)$pre_matches[0][$index][1]] = 'p'; 47 $htmltags[(int)$suf_matches[0][$index][1]] = 's'; 48 } 49 }else{ 50 foreach($pre_matches[0] as $index=>$pre_div){ 51 //非<div></div>格式,獲取前綴下標后的第一個>作為標簽結束 52 $suf_matches[0][$index][1] = stripos($data,'>',$pre_matches[0][$index][1])+1; 53 54 $htmltags[(int)$pre_matches[0][$index][1]] = 'p'; 55 $htmltags[(int)$suf_matches[0][$index][1]] = 's'; 56 } 57 } 58 //對所有HTML標簽按index進行排序 59 $sort = array_keys($htmltags); 60 asort($sort); 61 62 //開始獲取命中字符串 63 $hitTagStrings = array(); 64 foreach($hits[0] as $hit){ 65 $hit = $hit[1]; //獲取命中index 66 67 $count = count($sort); //循環控制,$count--避免無限循環 68 foreach($pre_matches[0] as $index=>$pre_div){ 69 //最后一個$pre_matches[0][$index+1]會造成數組出界,因此設置其index等于總長度 70 if(!isset($pre_matches[0][$index+1][1])) $pre_matches[0][$index+1][1] = strlen($data); 71 72 //<div $hit <div+1 時div被命中 73 if(($pre_matches[0][$index][1] <= $hit) && ($hit < $pre_matches[0][$index+1][1])){ 74 $deeper = 0; 75 //彈出被命中HTML標簽前的所有HTML標簽 76 while(array_shift($sort) != $pre_matches[0][$index][1] && ($count--)) continue; 77 //對剩余HTML標簽進行匹配,若下一個為前綴(p),則向下一層,$deeper加1, 78 //否則后退一層,$deeper減1,$deeper為0則命中匹配結束標記,計算div長度 79 foreach($sort as $key){ 80 if($htmltags[$key] == 'p') { //進入子層 81 $deeper++; 82 }else if($deeper == 0) { //碰到結束標記 83 $length = $key-$pre_matches[0][$index][1]; //長度等于結束標記index 減去 前綴index 84 break; 85 }else { //碰到子層結束標記 86 $deeper--; 87 } 88 } 89 $hitTagStrings[] = substr($data,$pre_matches[0][$index][1],$length).$endTag; 90 break; 91 } 92 } 93 //若只獲取第一個匹配項,退出循環 94 if($first && count($hitTagStrings) == 1) break; 95 } 96 97 return $hitTagStrings; 98 } 99 100 //直接用例 101 var_dump(getWebTag('id="nav"','http://mail.163.com/html/mail_intro/','ul')); 102 103 /* //注釋這句即可顯示 104 //ajax請求用例,必要參數:dataType:'json',type:'POST' 105 $tag_id = urldecode($_POST['tag_id']); 106 $url = urldecode($_POST['url']); 107 $tag = isset($_POST['tag'])? urldecode($_POST['tag']) : 'div'; 108 $data = urldecode($_POST['data']); 109 $first = (urldecode($_POST['first']) == 'checked')? true : false; 110 foreach($_POST as $key => $value){ 111 if($value == 'EmPtYValue') $$key = false; 112 } 113 echo json_encode(getWebTag($tag_id,$url,$tag,$data,$first)); 114 //*/ 115 116 //End_php?
2.虛擬POST數據至遠程服務器并獲取返回數據
View Code 1 <?php 2 header("Content-type: text/html; charset=utf-8"); 3 /** 4 * $url web url 5 * $post POST data 6 * @example 7 $data = array ( 8 'type' => 'text', 9 'inputValue' => '哈哈' 10 ); 11 $result = Post('http://tool.anzhuoxiazai.com:80//servlet/QRServlet', $data); 12 echo str_replace("src='","src='http://tool.anzhuoxiazai.com/",$result); 13 */ 14 function Post($url, $post = null) { 15 $context = array(); 16 if (is_array($post)) { 17 ksort($post); 18 $context['http'] = array ( 19 'timeout'=>60, 20 'method' => 'POST', 21 'content' => http_build_query($post) 22 ); 23 } 24 return file_get_contents($url, false, stream_context_create($context)); 25 } 26 27 $data = array ( 28 'type' => 'text', 29 'inputValue' => '哈哈' 30 ); 31 $result = Post('http://tool.anzhuoxiazai.com:80//servlet/QRServlet', $data); 32 echo str_replace("src='","src='http://tool.anzhuoxiazai.com/",$result); 33 //End_php?
3.文件夾復制
View Code 1 /** 2 * Copy file or folder from source to destination, it can do 3 * recursive copy as well and is very smart 4 * It recursively creates the dest file or directory path if there weren't exists 5 * Situtaions : 6 * - Src:/home/test/file.txt ,Dst:/home/test/b ,Result:/home/test/b -> If source was file copy file.txt name with b as name to destination 7 * - Src:/home/test/file.txt ,Dst:/home/test/b/ ,Result:/home/test/b/file.txt -> If source was file Creates b directory if does not exsits and copy file.txt into it 8 * - Src:/home/test ,Dst:/home/ ,Result:/home/test/** -> If source was directory copy test directory and all of its content into dest 9 * - Src:/home/test/ ,Dst:/home/ ,Result:/home/**-> if source was direcotry copy its content to dest 10 * - Src:/home/test ,Dst:/home/test2 ,Result:/home/test2/** -> if source was directoy copy it and its content to dest with test2 as name 11 * - Src:/home/test/ ,Dst:/home/test2 ,Result:->/home/test2/** if source was directoy copy it and its content to dest with test2 as name 12 * @todo 13 * - Should have rollback technique so it can undo the copy when it wasn't successful 14 * - Auto destination technique should be possible to turn off 15 * - Supporting callback function 16 * - May prevent some issues on shared enviroments : http://us3.php.net/umask 17 * @param $source //file or folder 18 * @param $dest ///file or folder 19 * @param $options //folderPermission,filePermission 20 * @return boolean 21 */ 22 function smartCopy($source, $dest, $options=array('folderPermission'=>0755,'filePermission'=>0755)) 23 { 24 $result=false; 25 26 if (is_file($source)) { 27 if ($dest[strlen($dest)-1]=='/') { 28 if (!file_exists($dest)) { 29 cmfcDirectory::makeAll($dest,$options['folderPermission'],true); 30 } 31 $__dest=$dest."/".basename($source); 32 } else { 33 $__dest=$dest; 34 } 35 $result=copy($source, $__dest); 36 chmod($__dest,$options['filePermission']); 37 38 } elseif(is_dir($source)) { 39 if ($dest[strlen($dest)-1]=='/') { 40 if ($source[strlen($source)-1]=='/') { 41 //Copy only contents 42 } else { 43 //Change parent itself and its contents 44 $dest=$dest.basename($source); 45 @mkdir($dest); 46 chmod($dest,$options['filePermission']); 47 } 48 } else { 49 if ($source[strlen($source)-1]=='/') { 50 //Copy parent directory with new name and all its content 51 @mkdir($dest,$options['folderPermission']); 52 chmod($dest,$options['filePermission']); 53 } else { 54 //Copy parent directory with new name and all its content 55 @mkdir($dest,$options['folderPermission']); 56 chmod($dest,$options['filePermission']); 57 } 58 } 59 60 $dirHandle=opendir($source); 61 while($file=readdir($dirHandle)) 62 { 63 if($file!="." && $file!="..") 64 { 65 if(!is_dir($source."/".$file)) { 66 $__dest=$dest."/".$file; 67 } else { 68 $__dest=$dest."/".$file; 69 } 70 //echo "$source/$file ||| $__dest<br />"; 71 $result=smartCopy($source."/".$file, $__dest, $options); 72 } 73 } 74 closedir($dirHandle); 75 76 } else { 77 $result=false; 78 } 79 return $result; 80 }?
4.文件遍歷(可匹配模式)
View Code 1 /** 2 * 遍歷目錄并獲取所有目錄即文件,以數組array('dirs'=>$dirs,'files'=>$files)方式返回。 3 * @param $dir //搜索目錄 4 * @param $pattern // '*'搜索全部文件,可以智能匹配,如*.jpg 搜索jpg文件,*.{jpg,png}搜索jpg和png文件,區分大小寫!! 5 * @param $skip //排除遍歷文件,如"*.{jpg,png}"排除.jpg和.png類型文件 6 * @param $subInclude //默認遍歷子目錄,$subInclude設置為false則僅遍歷當前目錄 7 * @param @flag //glob函數的標記,有效標記如下: 8 GLOB_MARK - 在每個返回的項目中加一個斜線 9 GLOB_NOSORT - 按照文件在目錄中出現的原始順序返回(不排序) 10 GLOB_NOCHECK - 如果沒有文件匹配則返回用于搜索的模式 11 GLOB_NOESCAPE - 反斜線不轉義元字符 12 GLOB_BRACE - 擴充 {a,b,c} 來匹配 'a','b' 或 'c' 13 GLOB_ONLYDIR - 僅返回與模式匹配的目錄項 14 */ 15 function scandir_through($dir,$pattern='*',$skip=false,$subInclude=true,$flag=GLOB_BRACE){ 16 $dirs = array(); 17 $files = array(); 18 //獲取當前目錄下所有文件及文件夾 19 $items = glob($dir . '/*'); 20 21 //遍歷所有項目,若設置$subInclude為true,則繼續遍歷子目錄 22 for ($i = 0; $i < count($items); $i++) { 23 if ($subInclude && is_dir($items[$i])) { 24 $dirs[] = iconv('gb2312','utf-8',$items[$i]); 25 $add = glob($items[$i] . '/*'); 26 if($add === false) $add = array(); 27 $items = array_merge($items, $add); 28 }else { 29 $slash = strrpos($items[$i],'/'); 30 $dir = substr($items[$i],0,$slash); 31 //若當前文件匹配文件查找模式$pattern,則加入$files數組中 32 if(in_array($items[$i],glob($dir.'/'.$pattern,$flag)) && (($skip===false) || !in_array($items[$i],glob($dir.'/'.$skip,$flag)))) { 33 $items[$i] = iconv('gb2312','utf-8',$items[$i]); 34 $file = substr($items[$i],$slash+1); 35 $files[] = $items[$i]; 36 } 37 } 38 } 39 return array('dirs'=>$dirs,'files'=>$files); 40 }?
5.zip壓縮文件夾
View Code 1 /** 2 * 打包文件夾成zip文件函數 3 * @param $path //打包文件夾路徑 4 * @param $zip //ZipArchive 對象 5 */ 6 function addFileToZip($path, $zip) { 7 $handler = opendir($path); //打開當前文件夾由$path指定。 8 /* 9 循環的讀取文件夾下的所有文件和文件夾 10 其中$filename = readdir($handler)是每次循環的時候將讀取的文件名賦值給$filename, 11 為了不陷于死循環,所以還要讓$filename !== false。 12 一定要用!==,因為如果某個文件名如果叫'0',或者某些被系統認為是代表false,用!=就會停止循環 13 */ 14 while (($filename = readdir($handler)) !== false) { 15 if ($filename != "." && $filename != "..") {//文件夾文件名字為'.'和‘..’,不要對他們進行操作 16 if (is_dir($path . "/" . $filename)) {// 如果讀取的某個對象是文件夾,則遞歸 17 addFileToZip($path . "/" . $filename, $zip); 18 } else { //將文件加入zip對象 19 $zip->addFile($path . "/" . $filename); 20 } 21 } 22 } 23 @closedir($path); 24 } 25 //運用 26 $zip = new ZipArchive(); 27 if ($zip->open('test.zip', ZipArchive::OVERWRITE) === TRUE) { 28 addFileToZip('./testdir', $zip); //調用方法,對要打包的根目錄進行操作,并將ZipArchive的對象傳遞給方法 29 $zip->close(); //關閉處理的zip文件 30 }?
?6.打印兩個日期之間的日期
View Code 1 function prDates($start, $end) { 2 //將ISO Date 轉成 Timestamp 3 $dt_start = strtotime($start); 4 $dt_end = strtotime($end); 5 do { 6 //將 Timestamp 轉成 ISO Date 輸出 7 echo date('Y-m-d', $dt_start).PHP_EOL; 8 } while (($dt_start += 86400) <= $dt_end); // 重復 Timestamp + 1 天(86400), 直至大于結束日期中止 9 }?
?7.RC4加密算法
View Code 1 /* 2 * rc4加密算法,二次加密即可還原 3 * $pwd 密鑰 4 * $data 要加密的數據 5 */ 6 function rc4 ($pwd, $data)//$pwd密鑰 $data需加密字符串 7 { 8 $key[] =""; 9 $box[] =""; 10 11 $pwd_length = strlen($pwd); 12 $data_length = strlen($data); 13 14 for ($i = 0; $i < 256; $i++) 15 { 16 $key[$i] = ord($pwd[$i % $pwd_length]); 17 $box[$i] = $i; 18 } 19 20 for ($j = $i = 0; $i < 256; $i++) 21 { 22 $j = ($j + $box[$i] + $key[$i]) % 256; 23 $tmp = $box[$i]; 24 $box[$i] = $box[$j]; 25 $box[$j] = $tmp; 26 } 27 28 for ($a = $j = $i = 0; $i < $data_length; $i++) 29 { 30 $a = ($a + 1) % 256; 31 $j = ($j + $box[$a]) % 256; 32 33 $tmp = $box[$a]; 34 $box[$a] = $box[$j]; 35 $box[$j] = $tmp; 36 37 $k = $box[(($box[$a] + $box[$j]) % 256)]; 38 $cipher .= chr(ord($data[$i]) ^ $k); 39 } 40 41 return $cipher; 42 }?
?8.utf8_substr UTF8編碼字符串截取,解決中英文混雜截取
View Code 1 /** 2 * $sting 輸入字符串 3 * $start 截取起始位,默認為0 4 * $length 截取長度,中英文長度都為1,默認為'',跟輸入負數一樣截取至字符串結束。 5 * [\x00-\x7F] 匹配英文字符 6 * [\xC0-\xFF][\x80-\xBF]+ 匹配中文字符 7 * 模式修正符s 將換行當成普通字符,此時.*能匹配包括換行任意字符 8 */ 9 function utf8_substr($string, $start=0, $length=''){ 10 return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}' 11 .'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$length.'}).*#s','$1',$string); 12 }?
9.創建透明圖片
$image = imagecreatetruecolor(300,300); $transparent = imagecolorallocatealpha($image, 255, 255, 255,127); //創建透明背景色 imagecolortransparent($img, $transparent); imagefill($image, 0, 0, $transparent); //填充透明背景色 View Code?
?10.圖片灰白化
1 <?php 2 /** 3 * 圖片黑白處理 4 * @params $file 圖片地址 5 * @params $output 直接輸出 6 * @params $newFile 保存黑白圖片 7 * @usage 8 1、imageGray('test.png'); 9 2、imageGray('test.png',false,'test_gray.png'); 10 */ 11 function imageGray($file,$output=true,$newFile=false){ 12 if(preg_match('#\.(jpg|png|jpeg|gif)$#i',$file,$match)){ 13 //不同類型圖片讀取函數 14 $create_function = 'imagecreatefrom'.$match[1]; 15 //根據不同類型圖片創建圖片 16 $im = $create_function($file); 17 18 //過濾成灰色圖片 19 if($im) imagefilter($im, IMG_FILTER_GRAYSCALE); 20 21 //不同類型圖片寫入函數 22 $image_function = 'image'.$match[1]; 23 //輸出到瀏覽器端 24 if ($output) { 25 header ("Content-type: image/".$match[1]); 26 $image_function($im); 27 } 28 //保存黑白照片 29 if($newFile) { 30 $file = $newFile; 31 $image_function($im,$file); 32 } 33 //刪除圖片資源 34 imagedestroy($im); 35 } 36 return $file; 37 } 38 ?> View Code?
?11.域名授權認證
1 function checkAuthenticated() 2 { 3 //合法域名數組 4 $domain_array = array( 5 base64_encode(base64_encode('127.0.0.1')), 6 base64_encode(base64_encode('localhost')), 7 base64_encode(base64_encode('test.com')), 8 base64_encode(base64_encode('*.test.com')), 9 ); 10 //對域名數組系列化并進行base64編碼,為了安全,做了拼接處理,防止被直接解編碼反系列化獲取結果 11 $str = base64_encode(base64_encode(serialize($domain_array))."|".serialize($domain_array)); 12 //解編碼,分離拼接 13 $arr = explode("|",base64_decode($str)); 14 //獲取數據系列化部分,反系列化得到域名數組 15 $arr = unserialize($arr[1]); 16 //遍歷域名數組,解編碼獲取域名 17 foreach($arr as $k=>$v) 18 { 19 $arr[$k] = base64_decode(base64_decode($v)); 20 } 21 //獲取當前URL的host地址 22 $host = $_SERVER['HTTP_HOST']; 23 //host:端口 分離 24 $host = explode(":",$host); 25 //去除端口部分 26 $host = $host[0]; 27 //認證通過標志,默認未通過認證 28 $passed = false; 29 //遍歷域名數組 30 foreach($arr as $k=>$v) 31 { 32 //帶通配子域名情況,使用preg_match進行匹配檢測 33 if(substr($v,0,2)=='*.') 34 { 35 $preg_str = substr($v,2); //去掉通配部分 36 if(preg_match("/".$preg_str."$/",$host)>0) //preg_match('/test.com$/','www.test.com') ,$preg_str中的.可匹配任意字符,包括. 37 { 38 $passed = true; //匹配通過,退出循環 39 break; 40 } 41 } 42 } 43 if(!$passed) //標志為假,因為foreach中為判斷非通配域名(test.com),因此還需要進行一次in_array判斷 44 { 45 if(!in_array($host,$arr)) 46 { 47 return false; 48 } 49 } 50 return true; 51 } View Code?
12.獲取文件權限值
1 function getChmod($filepath){ 2 return substr(base_convert(@fileperms($filepath),10,8),-4); 3 }?
13.數組不定長多鍵值排序
1 <?php 2 /** 3 * PHP數組不定長多鍵值排序 4 * 5 * @param array $list 數據源 6 * @param array $rules 排序規則 ['key1'=>'asc', 'key2' => 'desc', ...] 7 * @return array 8 */ 9 function smartMultiSort($list, $rules) { 10 $multisortParams = []; 11 foreach($rules as $key => $sort) { 12 $multisortParams[$key] = []; 13 $multisortParams[$key . $sort] = constant(strtoupper("sort_{$sort}")); 14 } 15 foreach($list as $item) { 16 foreach($rules as $key => $sort) { 17 $multisortParams[$key][] = $item[$key]; 18 } 19 } 20 $multisortParams[] = &$list; 21 22 call_user_func_array('array_multisort', $multisortParams); 23 return array_pop($multisortParams); 24 } 25 26 //示例 27 $list = array (); 28 $list [] = array ( 29 'id' => 1, 30 'name' => '學生1', 31 'school' => '學校1', 32 'class' => '班級1' 33 ); 34 $list [] = array ( 35 'id' => 4, 36 'name' => '學生4', 37 'school' => '學校2', 38 'class' => '班級2' 39 ); 40 $list [] = array ( 41 'id' => 3, 42 'name' => '學生3', 43 'school' => '學校2', 44 'class' => '班級1' 45 ); 46 $list [] = array ( 47 'id' => 2, 48 'name' => '學生2', 49 'school' => '學校1', 50 'class' => '班級2' 51 ); 52 $list [] = array ( 53 'id' => 5, 54 'name' => '學生5', 55 'school' => '學校2', 56 'class' => '班級3' 57 ); 58 print_r(smartMultiSort($list, ['school' => 'desc','id' => 'asc'])); View Code?
總結
- 上一篇: 梦到前妻生病预示什么意思
- 下一篇: 梦到狗咬女儿是什么意思