<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                1.ArrayAccess ArrayAccess 是PHP標準庫(SPL)提供的一個接口,這意味著我們可以直接調用,該接口使得對對象的訪問像數組一樣 ``` <?php 2 class Test implements ArrayAccess 3 { 4 private $testData; 5 6 public function offsetExists($key) 7 { 8 return isset($this->testData[$key]); 9 } 10 11 public function offsetSet($key, $value) 12 { 13 $this->testData[$key] = $value; 14 } 15 16 public function offsetGet($key) 17 { 18 return $this->testData[$key]; 19 } 20 21 public function offsetUnset($key) 22 { 23 unset($this->testData[$key]); 24 } 25 } 26 27 $obj = new Test(); 28 29 //自動調用offsetSet方法 30 $obj['data'] = 'data'; 31 32 //自動調用offsetExists 33 if(isset($obj['data'])){ 34 echo 'has setting!'; 35 } 36 //自動調用offsetGet 37 var_dump($obj['data']); 38 39 //自動調用offsetUnset 40 unset($obj['data']); 41 var_dump($test['data']); 42 43 //輸出: 44 //has setting! 45 //data 46 //null ``` 2.# IteratorAggregate聚合式迭代器 ``` <?php /** * 利用聚合式迭代器,并返回一個實現了Iterator接口的類的實例 * * @author 瘋狂老司機 */ class myData implements IteratorAggregate { public $one = "Public property one"; public $two = "Public property two"; public $three = "Public property three"; public function __construct() { $this->last = "last property"; } public function getIterator() { return new ArrayIterator($this); } } $obj = new myData; foreach($obj as $key => $value) { var_dump($key, $value); echo '<br>';// Linux:echo "\n"; } 以上例子輸出: string 'one' (length=3) string 'Public property one' (length=19) string 'two' (length=3) string 'Public property two' (length=19) string 'three' (length=5) string 'Public property three' (length=21) string 'last' (length=4) string 'last property' (length=13) ``` 3.# ArrayIterator迭代器遍歷數組 ``` <?php namespace app\index\controller; use ArrayObject;//引入迭代器 class Index { public function index() { $fruits = array( "apple" => 'apple value',//position =0 "orange" => 'orange value',//position =1 "grape" => 'grape value', "plum" => 'plum value', ); dump($fruits); echo '------------------普通數組遍歷-----------------'."<br/>"; foreach ($fruits as $key => $value) { echo $key.":".$value."<br/>"; } echo '------------------使用ArrayIterator迭代器遍歷數組(foreach)-----------------'."<br/>"; $obj = new ArrayObject($fruits);//創建數組對象 $it = $obj->getIterator();//獲取迭代器 foreach ($it as $key => $value) { echo $key.":".$value."<br/>"; } ``` 4.繼承Countable接口的可被用于count() 函數。 ``` <?php class Basket implements Countable{ private $fruits =array('apple','banna','pear','orange','watermelon'); public function count(){ return count($this->fruits); } } $basket = new Basket(); var_dump(count($basket)); ``` 5.# PHP 異常與錯誤 —— InvalidArgumentException ~~~ class InvalidArgumentException extends LogicException implements Throwable{ /* 繼承方法 */ final public string Exception::getMessage ( void ) // 獲取拋出的消息內容 final public Throwable Exception::getPrevious ( void ) // 返回上一個 Throwable final public mixed Exception::getCode ( void ) // 獲取拋出的錯誤代碼 final public string Exception::getFile ( void ) // 獲取產生異常的文件名 final public int Exception::getLine ( void ) // 獲取相關行號 final public array Exception::getTrace ( void ) // 獲取追蹤信息,返回數組形式 final public string Exception::getTraceAsString ( void ) // 獲取追蹤信息,返回字符串形式 public string Exception::__toString ( void ) // 拋出的對象以字符串形式返回,可以用 echo 打印相應結果 final private void Exception::__clone ( void ) // 嘗試克隆異常,將導致一個致命錯誤 } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看