欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網
          最全最豐富的資訊網站

          php高級函數有哪些

          php高級函數有哪些

          PHP高級函數

          1、call_user_func

          // 官網地址: http://php.net/manual/zh/function.call-user-func.php

          2、get_class

          // 官網地址: http://php.net/manual/zh/function.get-class.php

          3、get_called_class

          // 官網地址: http://php.net/manual/zh/function.get-called-class.php

          4、array_map

          // 官網地址:http://php.net/manual/zh/function.array-map.php //為數組的每個元素應用回調函數 示例: $str = '1 ,2,3'; $res = array_map(function ($v) {     return intval(trim($v)) * 2; }, explode(',', $str)); $res的返回結果: array(3) { [0]=> int(2) [1]=> int(4) [2]=> int(6) }

          5、strpos

           // http://php.net/manual/zh/function.strpos.php //查找字符串首次出現的位置,從0開始編碼,沒有找到返回false 示例: $time = "2019-03-02 12:00:00"; if(strpos($time,':') !== false){     $time = strtotime($time); } echo $time;

          6、array_reverse

          // 官網地址:http://php.net/manual/zh/function.array-reverse.php //返回單元順序相反的數組 示例: $time = "12:13:14"; $arrTime = array_reverse(explode(':',$time)); var_dump($arrTime); array(3) { [0]=> string(2) "14" [1]=> string(2) "13" [2]=> string(2) "12" }

          7、pow

          // 官網地址:http://php.net/manual/zh/function.pow.php //指數表達式 示例: $time = "12:13:14"; $arrTime = array_reverse(explode(':',$time)); $i = $s = 0; foreach($arrTime as $time){     $s += $time * pow(60,$i);  // 60 的 $i 次方     $i ++; } var_dump($s); int(43994)

          8、property_exist

          // 官網地址:http://php.net/manual/zh/function.property-exists.php // 檢查對象或類是否具有該屬性 //如果該屬性存在則返回 TRUE,如果不存在則返回 FALSE,出錯返回 NULL 示例: class Test {     public $name = 'daicr';     public function index()     {         var_dump(property_exists($this,'name')); // true     } }

          9、passthru

          // 官網地址:http://php.net/manual/zh/function.passthru.php //執(zhí)行外部程序并且顯示原始輸出 //功能和exec() system() 有類似之處 示例: passthru(Yii::$app->basePath.DIRECTORY_SEPARATOR . 'yii test/index');

          10、array_filter

          // 官網地址:http://php.net/manual/zh/function.array-filter.php //用回調函數過濾數組中的單元 示例: class TestController extends yiiconsoleController {     public $modules = '';     public function actionIndex()     {         //當不使用callBack函數時,array_filter會去除空值或者false         $enableModules = array_filter(explode(',',$this->modules));         var_dump(empty($enableModules)); //true         //當使用callBack函數時,就會用callBack過濾數組中的單元         $arr = [1,2,3,4];         $res = array_filter($arr,function($v){            return $v & 1;  //先轉換為二進制,在按位進行與運算,得到奇數         });         var_dump($res);         //array(2) { [0]=> int(1) [2]=> int(3) }     } }

          11、current

          // 官網地址:http://php.net/manual/zh/function.current.php //返回數組中的當前單元 $arr = ['car'=>'BMW','bicycle','airplane']; $str1 = current($arr); //初始指向插入到數組中的第一個單元。 $str2 = next($arr);    //將數組中的內部指針向前移動一位 $str3 = current($arr); //指針指向它“當前的”單元 $str4 = prev($arr);    //將數組的內部指針倒回一位 $str5 = end($arr);     //將數組的內部指針指向最后一個單元 reset($arr);           //將數組的內部指針指向第一個單元 $str6 = current($arr); $key1 = key($arr);     //從關聯(lián)數組中取得鍵名 echo $str1 . PHP_EOL; //BMW echo $str2 . PHP_EOL; //bicycle echo $str3 . PHP_EOL; //bicycle echo $str4 . PHP_EOL; //BMW echo $str5 . PHP_EOL; //airplane echo $str6 . PHP_EOL; //BMW echo $key1 . PHP_EOL; //car var_dump($arr);   //原數組不變

          12、array_slice

          // 官網地址:http://php.net/manual/zh/function.array-slice.php //從數組中取出一段 示例: $idSet = [1,2,3,4,5,6,7,8,9,10]; $total = count($idSet); $offset = 0; $success = 0; while ($offset < $total){     $arrId = array_slice($idSet,$offset,5);     //yii2的語法,此處,注意array_slice的用法就行     $success += $db->createCommand()->update($table,['sync_complate'=>1],['id'=>$arrId])->execute();      $offset += 50; } $this->stdout('共:' . $total . ' 條,成功:' . $success . ' 條' . PHP_EOL,Console::FG_GREEN); //yii2的語法

          13、mb_strlen()

          // 官網地址:http://php.net/manual/zh/function.mb-strlen.php //獲取字符串的長度 //strlen 獲取的是英文字節(jié)的字符長度,而mb_stren可以按編碼獲取中文字符的長度 示例: $str1 = 'daishu'; $str2 = '袋鼠'; echo strlen($str1) . PHP_EOL;                //6 echo mb_strlen($str1,'utf-8') . PHP_EOL;  //6 echo strlen($str2) . PHP_EOL;               // 4 一個中文占 2 個字節(jié) echo mb_strlen($str2,'utf-8') . PHP_EOL;  //2 echo mb_strlen($str2,'gb2312') . PHP_EOL; //2

          14、list

          // 官網地址:http://php.net/manual/zh/function.list.php //把數組中的值賦給一組變量 示例: list($access,$department)= ['all','1,2,3']; var_dump($access); // all

          15、strcasecmp

          // 官網地址:https://www.php.net/manual/zh/function.strcasecmp.php //二進制安全比較字符串(不區(qū)分大小寫) //如果 str1 小于 str2 返回 < 0; 如果 str1 大于 str2 返回 > 0;如果兩者相等,返回 0。 示例: $str1 = 'chrdai'; $str2 = 'chrdai'; var_dump(strcasecmp($str1,$str2)); // int 0

          16、fopen rb

          // 官網地址:https://www.php.net/manual/zh/function.fopen.php //1、使用 'b' 來強制使用二進制模式,這樣就不會轉換數據,規(guī)避了widown和unix換行符不通導致的問題, //2、還有就是在操作二進制文件時如果沒有指定'b'標記,可能會碰到一些奇怪的問題,包括壞掉的圖片文件以及關于rn 字符的奇怪問題。 示例: $handle = fopen($filePath, 'rb');

          17、fseek

          // 官網地址:https://www.php.net/manual/zh/function.fseek.php //在文件指針中定位 //必須是在一個已經打開的文件流里面,指針位置為:第三個參數 + 第二個參數 示例: //將文件指針移動到文件末尾 SEEK_END + 0 fseek($handle, 0, SEEK_END);

          18、ftell

          // 官網地址:https://www.php.net/manual/zh/function.ftell.php //返回文件指針讀/寫的位置 //如果將文件的指針用fseek移動到文件末尾,在用ftell讀取指針位置,則指針位置即為文件大小。 示例: //將文件指針移動到文件末尾 SEEK_END + 0 fseek($handle, 0, SEEK_END); //此時文件大小就等于指針的偏移量 $fileSize = ftell($handle);

          19、basename

          // 官網地址:https://www.php.net/manual/zh/function.basename.php //返回路徑中的文件名部分 示例: echo basename('/etc/sudoers.d');   // sudoers ,注意沒有文件的后綴名,和pathinfo($filePath)['filename']功能差不多

          20、pathinfo

          // 官網地址:https://www.php.net/manual/zh/function.pathinfo.php //返回文件路徑的信息 示例: $pathParts = pathinfo('/etc/php.ini'); echo $pathParts['dirname'] . PHP_EOL;     // /etc ,返回路徑信息中的目錄部分 echo $pathParts['basename'] . PHP_EOL;  // php.ini ,包括文件名和拓展名 echo $pathParts['extension'] . PHP_EOL; // ini ,拓展名 echo $pathParts['filename'] . PHP_EOL;  // php ,只有文件名,不包含拓展名 ,和basename()函數功能差不多

          21、headers_sent($file, $line)

          // 官網地址:https://www.php.net/manual/zh/function.headers-sent.php //檢測 HTTP 頭是否已經發(fā)送 //1、http頭已經發(fā)送時,就無法通過header()函數添加

          贊(0)
          分享到: 更多 (0)
          網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號