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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

bool(true)
bool(false)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

bool(true)
bool(false)
bool(false)

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.