<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語言

            PHP的ArrayAccess接口

            時間:2025-05-23 02:58:49 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;//一個包含著數據庫訪問方法的對象

              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支付寶接口用法分析04-07

            php面向對象全攻略 php5接口技術06-18

            PHP面向對象程序設計之接口用法07-08

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

            Java接口介紹05-08

            php學習之php配置07-15

            PHP學習:PHP拼音類01-25

            php正則去掉php注釋07-30

            php與php MySQL之間的關系03-03

            <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>
                      黄色视频在线观看