Open In App

PHP SplObjectStorage removeAll() Function

Last Updated : 23 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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));
?>


Output:

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));
  
?>


Output:

int(2)
int(1)
int(0)

Reference: https://www.php.net/manual/en/splobjectstorage.removeall.php



Similar Reads

PHP SplObjectStorage contains() Function
The SplObjectStorage::contains() function is an inbuilt function in PHP which is used to check the storage object contains a specified object or not. Syntax: bool SplObjectStorage::contains( $value ) Parameters: This function accepts a single parameter $value which specifies the storage object which is going to check. Return Value: This function re
1 min read
PHP SplObjectStorage count() Function
The SplObjectStorage::count() function is an inbuilt function in PHP which is used to count the number of objects in storage. Syntax: int SplObjectStorage::count() Parameters: This function does not contains any parameter. Return Value: This function returns number of objects in storage. Below programs illustrate the SplObjectStorage::count() funct
1 min read
PHP SplObjectStorage addAll() Function
The SplObjectStorage::addAll() function is an inbuilt function in PHP which is used to add elements from another storage. Syntax: void SplObjectStorage::addAll( $value ) Parameters: This function accepts a single parameter $value which holds an storage which need to import. Return Value: It does not return any value. Below programs illustrate the S
1 min read
PHP SplObjectStorage valid() Function
The SplObjectStorage::valid() function is an inbuilt function in PHP which is used to check the current storage entry is valid or not. Syntax: bool SplObjectStorage::valid() Parameters: This function does not accept any parameter. Return Value: This function returns true if the iterator entry is valid, false otherwise. Below programs illustrate the
1 min read
PHP SplObjectStorage attach() Function
The SplObjectStorage::attach() function is an inbuilt function in PHP which is used to add objects into the SplObjectStorage. Syntax: void SplObjectStorage::attach($obj, $val) Parameters: This function accepts two parameters as mention above and described below. $obj: This is required parameter which specifies the object of the storage class. $val:
1 min read
PHP SplObjectStorage current() Function
The SplObjectStorage::current() function is an inbuilt function in PHP which is used get the current entry of storage. Syntax: object SplObjectStorage::current() Parameters: This function does not accept any parameter. Return Value: This function returns the object of the current storage. Below programs illustrate the SplObjectStorage::current() fu
1 min read
PHP SplObjectStorage next() Function
The SplObjectStorage::next() function is an inbuilt function in PHP which is used to move to next entry of storage. Syntax: void SplObjectStorage::next() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs illustrate the SplObjectStorage::next() function in PHP: Program 1: P
1 min read
PHP SplObjectStorage detach() Function
The SplObjectStorage::detach() function is an inbuilt function in PHP which is used to remove objects from the storage. Syntax: void SplObjectStorage::detach($obj) Parameters: This function accepts a single parameter $obj which specifies the object to be remove from the storage. Return Value: This function does not return any value. Below programs
1 min read
PHP SplObjectStorage getinfo() Function
The SplObjectStorage::getinfo() function is an inbuilt function in PHP that is used to get the data associated with the object by the current iterator position. Syntax: mixed SplObjectStorage::getinfo() Parameters: This function does not accept any parameter. Return Value: This function returns the object associated by the current iterator position
1 min read
PHP SplObjectStorage key() Function
The SplObjectStorage::key() function is an inbuilt function in PHP which is used to get the index of the currently pointing iterator. Syntax: int SplObjectStorage::key() Parameters: This function does not accept any parameter. Return Value: This function returns the index at which the iterator currently pointing. Below programs illustrate the SplOb
1 min read