亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP SplObjectStorage使用實(shí)例

 更新時(shí)間:2015年05月12日 09:09:20   投稿:junjie  
這篇文章主要介紹了PHP SplObjectStorage使用實(shí)例,SplObjectStorage是SPL標(biāo)準(zhǔn)庫中的數(shù)據(jù)結(jié)構(gòu)對(duì)象容器,用來存儲(chǔ)一組對(duì)象,特別是當(dāng)你需要唯一標(biāo)識(shí)對(duì)象的時(shí)候,需要的朋友可以參考下

PHP SPL SplObjectStorage是用來存儲(chǔ)一組對(duì)象的,特別是當(dāng)你需要唯一標(biāo)識(shí)對(duì)象的時(shí)候。
PHP SPL SplObjectStorage類實(shí)現(xiàn)了Countable,Iterator,Serializable,ArrayAccess四個(gè)接口。可實(shí)現(xiàn)統(tǒng)計(jì)、迭代、序列化、數(shù)組式訪問等功能。

看下面一個(gè)簡(jiǎn)單的例子:

class A {
  public $i;
  public function __construct($i) {
    $this->i = $i;
  }
}
 
$a1 = new A(1);
$a2 = new A(2);
$a3 = new A(3);
$a4 = new A(4);
 
$container = new SplObjectStorage();
 
//SplObjectStorage::attach 添加對(duì)象到Storage中
$container->attach($a1);
$container->attach($a2);
$container->attach($a3);
 
//SplObjectStorage::detach 將對(duì)象從Storage中移除
$container->detach($a2);
 
//SplObjectStorage::contains用于檢查對(duì)象是否存在Storage中
var_dump($container->contains($a1)); //true
var_dump($container->contains($a4)); //false
 
//遍歷
$container->rewind();
while($container->valid()) {
  var_dump($container->current());
  $container->next();
}

相關(guān)文章

最新評(píng)論