PHP | SplObjectStorage offsetExists() Function
The SplObjectStorage::offsetExists() function is an inbuilt function in PHP which is used to check the object exist in storage or not.
Syntax:
bool SplObjectStorage::offsetExists($object)
Parameters: This function accepts a single parameter $object which specifies the object to be checked.
Return Value: This function returns true if object exist in storage otherwise return false.
Below programs illustrate the SplObjectStorage::offsetExists() function in PHP:
Program 1:
<?php // Create an empty SplObjectStorage $str = new SplObjectStorage; $obj = new StdClass; // Attch $obj to $str $str->attach($obj); // Print Result var_dump($str->offsetExists($obj)); ?> |
bool(true)
Program 2:
<?php // Create an Empty SplObjectStorage $str = new SplObjectStorage(); $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $obj4 = new StdClass; // Attach only three objects $str->attach($obj1, "GeksforGeeks"); $str->attach($obj2, "GFG"); $str->attach($obj3); // Print result var_dump($str->offsetExists($obj1)); var_dump($str->offsetExists($obj2)); var_dump($str->offsetExists($obj4)); var_dump($str->offsetExists($obj3)); ?> |
bool(true) bool(true) bool(false) bool(true)
Reference: https://www.php.net/manual/en/splobjectstorage.offsetexists.php
Recommended Posts:
- PHP | SplDoublyLinkedList offsetExists() Function
- ArrayObject offsetExists() Function in PHP
- PHP | SplFixedArray offsetExists() Function
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage removeAllExcept() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage unserialize() Function
- PHP | SplObjectStorage setInfo() Function
- PHP | SplObjectStorage serialize() Function
- PHP | SplObjectStorage rewind() Function
- PHP | SplObjectStorage getinfo() 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.



