<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            PHP的ArrayAccess接口

            時間:2025-10-27 16:15:19 php語言

            PHP的ArrayAccess接口

              如果想讓對象使用起來像一個 PHP 數組,那么我們需要實現 ArrayAccess 接口,就跟隨百分網小編一起去了解下吧,想了解更多相關信息請持續關注我們應屆畢業生考試網!

              代碼如下:

              interface ArrayAccess

              boolean offsetExists($index)

              mixed offsetGet($index)

              void offsetSet($index, $newvalue)

              void offsetUnset($index)

              下面的例子展示了如何使用這個接口,例子并不是完整的,但是足夠看懂,:->

              復制代碼 代碼如下:

              <?php

              class UserToSocialSecurity implements ArrayAccess

              {

              private $db;/pic/p>

              function offsetExists($name)

              {

              return $this->db->userExists($name);

              }

              function offsetGet($name)

              {

              return $this->db->getUserId($name);

              }

              function offsetSet($name, $id)

              {

              $this->db->setUserId($name, $id);

              }

              function offsetUnset($name)

              {

              $this->db->removeUser($name);

              }

              }

              $userMap = new UserToSocialSecurity();

              print "John's ID number is " . $userMap['John'];

              ?>

              實際上,當 $userMap['John'] 查找被執行時,PHP 調用了 offsetGet() 方法,由這個方法再來調用數據庫相關的 getUserId() 方法。

            【PHP的ArrayAccess接口】相關文章:

            php支付寶接口用法分析12-08

            php面向對象全攻略 php5接口技術02-23

            PHP面向對象程序設計之接口用法01-28

            php根據IP地址獲取當前地理位置接口12-16

            Java接口介紹12-20

            CPU的接口類型02-03

            電腦主板接口使用12-08

            java面向接口編程02-19

            java語言的接口與繼承02-26

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看