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;
$str = new SplObjectStorage();
$str[$gfg1] = "GeeksforGeeks";
var_dump($str->contains($gfg1));
var_dump($str->contains($gfg2));
?>
|
Output:
bool(true)
bool(false)
Program 2:
<?php
$gfg1 = new StdClass;
$gfg2 = new StdClass;
$str = new SplObjectStorage();
$str[$gfg1] = "GeeksforGeeks";
var_dump($str->contains($gfg1));
var_dump($str->contains($gfg2));
$str->detach($gfg1);
var_dump($str->contains($gfg1));
?>
|
Output:
bool(true)
bool(false)
bool(false)
Reference: https://www.php.net/manual/en/splobjectstorage.contains.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Jun, 2023
Like Article
Save Article