PHP SplObjectStorage setInfo () function

PHP

Syntax:
void SplObjectStorage::setInfo ($val)
Parameters: This function takes one parameter, $val,which specifies the data to be associated with the current iterator record in the store.Return value:this function is not returns no value.The following programs illustrate the function SplObjectStorage::setInfo()in PHP:Program 1: $str = new SplObjectStorage(); $obj1 = new StdClass; $str -> attach ( $obj1 , " GeeksforGeeks " ); $str -> rewind ();  
// Set new information for $obj1 in the $str repository $str -> setInfo ( "new_GeeksforGeeks " );  
// Print the result var_dump ( $str [ $obj1 ]); ?>
Exit:
string (17 ) "new_GeeksforGeeks"
Program 2: $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $gfg = new SplObjectStorage(); $gfg [ $obj1 ] = "GFG" ; $gfg [ $obj2 ] = "GeeksClasses" ; $gfg [ $obj3 ] = "SUDO" ;  
// Using the rewind function $gfg -> rewind (); while ( $gfg -> valid()) { $gfg -> setInfo ( " Modified_GFG_DATA " ); var_dump ( $gfg -> getInfo()); // Move to next element $gfg -> next(); }
?>
Exit:
string (17 ) "Modified_GFG_DATA" string (17) "Modified_GFG_DATA" string (17) "Modified_GFG_DATA"
Link: https://www.php.net/manual/en/splobjectstorage.setinfo.php



Get Solution for free from DataCamp guru