PHP Conference Japan 2024

SplObjectStorage::removeAll

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

SplObjectStorage::removeAll從目前的儲存區移除另一個儲存區中包含的物件

說明

public SplObjectStorage::removeAll(SplObjectStorage $storage): int

從目前的儲存區移除另一個儲存區中包含的物件。

參數

storage

包含要移除之元素的儲存區。

回傳值

返回剩餘物件的數量。

範例

範例 #1 SplObjectStorage::removeAll() 範例

<?php
$o1
= new stdClass;
$o2 = new stdClass;
$a = new SplObjectStorage();
$a[$o1] = "foo";

$b = new SplObjectStorage();
$b[$o1] = "bar";
$b[$o2] = "gee";

var_dump(count($b));
$b->removeAll($a);
var_dump(count($b));
?>

以上範例的輸出類似於:

int(2)
int(1)

另請參閱

新增註記

使用者貢獻的註記 1 則註記

10
rafal dot wrzeszcz at wrzasq dot pl
11 年前
您可以呼叫

$storage->removeAll($storage);

以移除所有元素。
To Top