The example Kirk provided is not the best option, there's a method "removeAll" that you can pass the SplObjectStore itself, and as the name says, remove all stored objects.
PHP.mk документација
SplObjectStorage::removeAllExcept
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
splobjectstorage.removeallexcept.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
splobjectstorage.removeallexcept.php
SplObjectStorage::removeAllExcept
Референца за `splobjectstorage.removeallexcept.php` со подобрена типографија и навигација.
SplObjectStorage::removeAllExcept
(PHP 5 >= 5.3.6, PHP 7, PHP 8)
SplObjectStorage::removeAllExcept — Removes all objects except for those contained in another storage from the current storage
= NULL
Removes all objects except for those contained in another storage from the current storage.
Параметри
storage-
The storage containing the elements to retain in the current storage.
Вратени вредности
Returns the number of remaining objects.
Примери
Пример #1 SplObjectStorage::removeAllExcept() example
<?php
$a = (object) 'a';
$b = (object) 'b';
$c = (object) 'c';
$foo = new SplObjectStorage;
$foo->attach($a);
$foo->attach($b);
$bar = new SplObjectStorage;
$bar->attach($b);
$bar->attach($c);
$foo->removeAllExcept($bar);
var_dump($foo->contains($a));
var_dump($foo->contains($b));
?>Горниот пример ќе прикаже нешто слично на:
bool(false) bool(true)
Белешки од корисници 2 забелешки
hizer at hizercache dot com ¶
пред 10 години
kirk at wa dot net dot ua ¶
пред 14 години
You may remove all elements by passing empty SplObjectStorage
$splStorage->removeAllExcept(new SplObjectStorage());