Sunday, December 29, 2024
Google search engine
HomeLanguagesPHP SplObjectStorage setInfo() Function

PHP SplObjectStorage setInfo() Function

The SplObjectStorage::setInfo() function is an inbuilt function in PHP which is used to set the data associated with the current iterator entry.

Syntax:

void SplObjectStorage::setInfo( $val )

Parameters: This function accepts a single parameter $val which specifies the data to be associate to the current iterator entry of the storage.

Return Value: This function does not return any value.

Below programs illustrate the SplObjectStorage::setInfo() function in PHP:

Program 1:




<?php
  
$str = new SplObjectStorage();
  
$obj1 = new StdClass;
  
$str->attach($obj1, "neveropen");
  
$str->rewind();
  
// Set new info for $obj1 in storage $str
$str->setInfo("new_neveropen");
  
// Print Result
var_dump($str[$obj1]);
?>


Output:

string(17) "new_neveropen"

Program 2:




<?php
  
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
  
$gfg = new SplObjectStorage();
$gfg[$obj1] = "GFG";
$gfg[$obj2] = "GeeksClasses";
$gfg[$obj3] = "SUDO";
  
// Using rewind function
$gfg->rewind();
  
while($gfg->valid()) {
  
    $gfg->setInfo("Modified_GFG_DATA");
    var_dump($gfg->getInfo());
      
    // Moving to next element
    $gfg->next();
}
?>


Output:

string(17) "Modified_GFG_DATA"
string(17) "Modified_GFG_DATA"
string(17) "Modified_GFG_DATA"

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments