SplObjectStorage::contains()函數是PHP中的內置函數,用於檢查存儲對象是否包含指定的對象。
用法:
bool SplObjectStorage::contains( $value )
參數:此函數接受單個參數$value,該參數指定要檢查的存儲對象。
返回值:如果存儲對象包含指定的對象,則此函數返回true,否則返回false。
以下程序說明了PHP中的SplObjectStorage::contains()函數:
程序1:
<?php
$gfg1 = new StdClass;
$gfg2 = new StdClass;
// Declare Empty SplObjectStorage
$str = new SplObjectStorage();
$str[$gfg1] = "GeeksforGeeks";
// Print result
var_dump($str->contains($gfg1));
var_dump($str->contains($gfg2));
?>
輸出:
bool(true) bool(false)
程序2:
<?php
$gfg1 = new StdClass;
$gfg2 = new StdClass;
// Declare Empty SplObjectStorage
$str = new SplObjectStorage();
$str[$gfg1] = "GeeksforGeeks";
// Print result
var_dump($str->contains($gfg1));
var_dump($str->contains($gfg2));
// detach and print result
$str->detach($gfg1);
var_dump($str->contains($gfg1));
?>
輸出:
bool(true) bool(false) bool(false)
參考: https://www.php.net/manual/en/splobjectstorage.contains.php
相關用法
- PHP SplObjectStorage key()用法及代碼示例
- PHP SplObjectStorage next()用法及代碼示例
- PHP SplObjectStorage setInfo()用法及代碼示例
- PHP SplObjectStorage detach()用法及代碼示例
- PHP SplObjectStorage serialize()用法及代碼示例
- PHP SplObjectStorage unserialize()用法及代碼示例
- PHP SplObjectStorage current()用法及代碼示例
- PHP SplObjectStorage offsetGet()用法及代碼示例
- PHP SplObjectStorage getinfo()用法及代碼示例
- PHP SplObjectStorage offsetExists()用法及代碼示例
- PHP SplObjectStorage offsetSet()用法及代碼示例
- PHP SplObjectStorage offsetUnset()用法及代碼示例
- PHP SplObjectStorage rewind()用法及代碼示例
- PHP SplObjectStorage removeAllExcept()用法及代碼示例
- PHP SplObjectStorage removeAll()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplObjectStorage contains() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。