久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      use關(guān)鍵字在php中的使用(含代碼)

      use關(guān)鍵字在php中的使用(含代碼)

      use關(guān)鍵字在php中的使用

      1、use最常用在給類取別名,還可以用在閉包函數(shù)中,代碼如下

      <?php function test() {     $a = 'hello';     return function ($a)use($a) {         echo $a . $a;     }; } $b = test(); $b('world');//結(jié)果是hellohello

      當(dāng)運行test函數(shù),test函數(shù)返回閉包函數(shù),閉包函數(shù)中的use中的變量為test函數(shù)中的$a變量,當(dāng)運行閉包函數(shù)后,輸出“hellohello”,由此說明函數(shù)體中的變量的優(yōu)先級是:use中的變量的優(yōu)先級比閉包函數(shù)參數(shù)中的優(yōu)先級要高。

      2、use中的參數(shù)也可以使用引用傳遞的,代碼如下

      示例一

      <?php function test() {     $a=18;     $b="Ly";     $fun = function($num, $name) use(&$a, &$b) {         $a = $num;         $b = $name;     };     echo "$b:$a<br/>";     $fun(30,'wq');     echo "$b:$a<br/>"; } test(); //結(jié)果是Ly:18 //結(jié)果是wq:30

      示例二

      <?php function index() { $a = 1; return function () use(&$a){ echo $a; $a++; }; } $a = index(); $a(); $a(); $a(); $a(); $a(); $a(); //123456 ?>

      感謝大家的觀看,希望在學(xué)習(xí)了use關(guān)鍵字的用法以后可以獲得提升。

      推薦教程:《PHP教程》

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