PHP | SplObjectStorage removeAll()函数
SplObjectStorage::removeAll()函数是PHP中的一个内置函数,用于从当前存储中删除另一个存储中包含的所有对象。
句法:
void SplObjectStorage::removeAll( $obj )
参数:此函数接受单个参数$obj ,它指定要从当前存储中删除的存储。
返回值:此函数不返回任何值。
下面的程序说明了PHP中的SplObjectStorage::removeAll()函数:
方案一:
removeAll($gfg1);
// Print result after removeAll
var_dump(count($gfg2));
?>
输出:
int(2)
int(1)
方案二:
removeAll($gfg1);
// Print result after removeAll
var_dump(count($gfg2));
// Remove all objects itself $gfg2
$gfg2->removeAll($gfg2);
// Print result after removeAll
var_dump(count($gfg2));
?>
输出:
int(2)
int(1)
int(0)
参考: https://www. PHP.net/manual/en/splobjectstorage.removeall。 PHP