欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

php語言

php函數(shù)連續(xù)調用實例分析

時間:2025-02-19 00:05:41 php語言 我要投稿
  • 相關推薦

php函數(shù)連續(xù)調用實例分析

  文章主要介紹了php函數(shù)連續(xù)調用的方法,以簡單實例形式分析了php采用鏈式調用的方式連續(xù)調用函數(shù)的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下。

  本文實例講述了php函數(shù)連續(xù)調用的方法。分享給大家供大家參考。具體如下:

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  <?php

  //返回$this,實現(xiàn)連續(xù)調用

  class xin {

  function name($namec) {

  echo "我的名字是:$namec <br/>";

  return $this;

  }

  function age($agec) {

  echo "我的年齡是:$agec <br/>";

  return $this;

  }

  }

  $xind = new xin();

  $xind->name("星星")->age("10000");

  ?>

  運行結果如下:

  我的名字是:星星

  我的年齡是:10000

  希望本文所述對大家的php程序設計有所幫助。

  【拓展閱讀】

  10個php函數(shù)實用卻不常見

  1. sys_getloadavg()

  sys_getloadavt()可以獲得系 統(tǒng)負載情況。該函數(shù)返回一個包含三個元素的數(shù)組,每個元素分別代表系統(tǒng)再過去的1、5和15分鐘內的平均負載。與其讓服務器因負 載過高而宕掉,不如在系統(tǒng)負載很高時主動die掉一個腳本,sys_getloadavg()就是用來幫你實現(xiàn)這個功能的。 不過很遺憾,該函數(shù)在windows下無效。

  2. pack()

  Pack() 能將md5()返回的32位16進制字符串轉換為16位的二進制字符串,可以節(jié)省存儲空間。

  3. cal_days_in_month()

  cal_days_in_month()能夠返回指定月份共有多少天。

  4. _()

  WordPress開發(fā)者經(jīng)常能見到這個函數(shù),還有 _e()。這兩個函數(shù)功能相同,與gettext()函數(shù)結合使用,能實現(xiàn)網(wǎng)站的多語言化。具體可參見PHP手冊的相關部分介紹。

  5. get_browser()

  在發(fā)送頁面前先看看用戶的`瀏覽器都能做些什么是 不是挺好?get_browser()能獲得用戶的瀏覽器類型,以及瀏覽器支持的功能,不過首先你需要一個php_browscap.ini文件,用來給 函數(shù)做參考文件。

  要注意,該函數(shù)對瀏覽器功能的判斷是基于該類瀏覽器的一般特性的。例如,如果用戶關閉了瀏覽器對 JavaScript的支持,函數(shù)無法得知這一點。但是在判斷瀏覽器類型和OS平臺方面,該函數(shù)還是很準確的。

  6. debug_print_backtrace()

  這是一個調試用的函數(shù),能幫助你發(fā)現(xiàn)代碼中的邏輯錯誤。要理 解這個函數(shù),還是直接看個例子吧:

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  16

  17

  18

  19

  20

  21

  22

  23

  24

  25

  26

  27

  28

  29

  30

  $a = 0;

  function iterate() {

  global $a;

  if( $a < 10 )

  recur();

  echo $a . “, “;

  }

  function recur() {

  global $a;

  $a++;

  // how did I get here?

  echo “\n\n\n”;

  debug_print_backtrace();

  if( $a < 10 )

  iterate();

  }

  iterate();

  # OUTPUT:

  #0 recur() called at [C:\htdocs\php_stuff\index.php:8]

  #1 iterate() called at [C:\htdocs\php_stuff\index.php:25]

  #0 recur() called at [C:\htdocs\php_stuff\index.php:8]

  #1 iterate() called at [C:\htdocs\php_stuff\index.php:21]

  #2 recur() called at [C:\htdocs\php_stuff\index.php:8]

  #3 iterate() called at [C:\htdocs\php_stuff\index.php:25]

  #0 recur() called at [C:\htdocs\php_stuff\index.php:8]

  #1 iterate() called at [C:\htdocs\php_stuff\index.php:21]

  #2 recur() called at [C:\htdocs\php_stuff\index.php:8]

  #3 iterate() called at [C:\htdocs\php_stuff\index.php:21]

  #4 recur() called at [C:\htdocs\php_stuff\index.php:8]

  #5 iterate() called at [C:\htdocs\php_stuff\index.php:25]

  7. metaphone()

  這個函數(shù)返回單詞的metaphone值,相同讀音的單詞具有相同的metaphone值,也就是說這個函數(shù)可以幫你判斷兩個單詞的讀音是否 相同。

  8. natsort()

  natsort()能將一個數(shù)組以自然排序法 進行排列,直接看個例子吧:

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  16

  17

  18

  19

  20

  21

  22

  23

  24

  $items = array(

  “100 apples”, “5 apples”, “110 apples”, “55 apples”

  );

  // normal sorting:

  sort($items);

  print_r($items);

  # Outputs:

  # Array

  # (

  # [0] => 100 apples

  # [1] => 110 apples

  # [2] => 5 apples

  # [3] => 55 apples

  # )

  natsort($items);

  print_r($items);

  # Outputs:

  # Array

  # (

  # [2] => 5 apples

  # [3] => 55 apples

  # [0] => 100 apples

  # [1] => 110 apples

  # )

  9. levenshtein()

  Levenshtein()告訴你兩個單詞之間的“距離”。它告訴你如果想把一個單詞變成另一個單詞,需要插入、替換和刪除多少字母。

  看個例子吧:

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  $dictionary = array(

  “php”, “javascript”, “css”

  );

  $word = “japhp”;

  $best_match = $dictionary[0];

  $match_value = levenshtein($dictionary[0], $word);

  foreach($dictionary as $w) {

  $value = levenshtein($word, $w);

  if( $value < $match_value ) {

  $best_match = $w;

  $match_value = $value;

  }

  }

  echo “Did you mean the ‘$best_match' category?”;

  10. glob()

  glob()會讓你覺得用 opendir(), readdir()和closedir()來尋找文件非常蠢。

  ?

  1

  2

  foreach (glob(“*.php”) as $file)

  echo “$file\n”;

【php函數(shù)連續(xù)調用實例分析】相關文章:

java調用c函數(shù)的實例04-25

C語言中Swift函數(shù)調用實例01-17

php之readdir函數(shù)用法實例02-07

PHP會話控制實例分析03-28

php中return的用法實例分析03-25

分析php過濾XSS攻擊的函數(shù)08-02

PHP5異常處理分析實例08-07

php表單提交與$-POST實例分析04-01

PHP調用的C代碼08-05