PHP | SplObjectStorage removeAll() Function
The SplObjectStorage::removeAll() function is an inbuilt function in PHP which is used to remove all objects contained in another storage from the current storage.
Syntax:
void SplObjectStorage::removeAll( $obj )
Parameters: This function accepts a single parameter $obj which specify the storage to be removed from the current storage.
Return Value: This function does not return any value.
Below programs illustrate the SplObjectStorage::removeAll() function in PHP:
Program 1:
<?php $obj1 = new StdClass; $obj2 = new StdClass; $gfg1 = new SplObjectStorage(); $gfg1[$obj1] = "Geeks"; $gfg2 = new SplObjectStorage(); $gfg2[$obj1] = "GFG"; $gfg2[$obj2] = "GeeksClasses"; // Count and print all existing objects var_dump(count($gfg2)); // Remove all objects of $gfg1 from $gfg2 $gfg2->removeAll($gfg1); // Print result after removeAll var_dump(count($gfg2)); ?> |
int(2) int(1)
Program 2:
<?php $obj1 = new StdClass; $obj2 = new StdClass; $gfg1 = new SplObjectStorage(); $gfg1[$obj1] = "Geeks"; $gfg2 = new SplObjectStorage(); $gfg2[$obj1] = "GFG"; $gfg2[$obj2] = "GeeksClasses"; // Count and print all existing objects var_dump(count($gfg2)); // Remove all objects of $gfg1 from $gfg2 $gfg2->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)
Reference: https://www.php.net/manual/en/splobjectstorage.removeall.php
Recommended Posts:
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage offsetGet() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage detach() Function
- PHP | SplObjectStorage getinfo() Function
- PHP | SplObjectStorage offsetSet() Function
- PHP | SplObjectStorage setInfo() Function
- PHP | SplObjectStorage unserialize() Function
- PHP | SplObjectStorage serialize() Function
- PHP | SplObjectStorage rewind() Function
- PHP | SplObjectStorage valid() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage removeAllExcept() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



