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 returns true if storage object contains specified object otherwise return false.
Below programs illustrate the SplObjectStorage::contains() function in PHP:
Program 1:
<?php $gfg1 = new StdClass; $gfg2 = new StdClass; // Declare Empty SplObjectStorage $str = new SplObjectStorage(); $str[$gfg1] = "GeeksforGeeks"; // Print result var_dump($str->contains($gfg1)); var_dump($str->contains($gfg2)); ?> |
bool(true) bool(false)
Program 2:
<?php $gfg1 = new StdClass; $gfg2 = new StdClass; // Declare Empty SplObjectStorage $str = new SplObjectStorage(); $str[$gfg1] = "GeeksforGeeks"; // Print result var_dump($str->contains($gfg1)); var_dump($str->contains($gfg2)); // detach and print result $str->detach($gfg1); var_dump($str->contains($gfg1)); ?> |
bool(true) bool(false) bool(false)
Reference: https://www.php.net/manual/en/splobjectstorage.contains.php
Recommended Posts:
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage getinfo() Function
- PHP | SplObjectStorage rewind() Function
- PHP | SplObjectStorage serialize() Function
- PHP | SplObjectStorage detach() Function
- PHP | SplObjectStorage offsetSet() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage offsetGet() Function
- PHP | SplObjectStorage removeAllExcept() Function
- PHP | SplObjectStorage count() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage addAll() Function
- PHP | SplObjectStorage current() 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.


