📜  PHP | SplObjectStorage next()函数

📅  最后修改于: 2022-05-13 01:56:31.917000             🧑  作者: Mango

PHP | SplObjectStorage next()函数

SplObjectStorage::next()函数是PHP中的一个内置函数,用于移动到存储的下一个条目。

句法:

void SplObjectStorage::next()

参数:此函数不接受任何参数。

返回值:此函数不返回任何值。

下面的程序说明了PHP中的SplObjectStorage::next()函数:

方案一:

attach($obj, "GFG");
$str->attach($obj2, "Geeks");
  
$str->rewind();
  
// Get the current data 
var_dump($str->getInfo());
  
// Move on to next object
$str->next();
  
// Print result of next entry
var_dump($str->getInfo());
?>
输出:
string(3) "GFG"
string(5) "Geeks"

方案二:

attach($obj1, "GeksforGeeks");
$str->attach($obj2, "GFG");
$str->attach($obj3);
$str->attach($obj4, "DSA");
   
$str->rewind();
   
// Iterate and print data on each index
while($str->valid()) {
      
    // Get index 
    $index  = $str->key();
    $object = $str->current(); 
    $data   = $str->getInfo();
   
    var_dump($index, $data);
      
    // Moving each time next entry
    $str->next();
}
?>
输出:
int(0)
string(12) "GeksforGeeks"
int(1)
string(3) "GFG"
int(2)
NULL
int(3)
string(3) "DSA"

参考: https://www. PHP.net/manual/en/splobjectstorage.next。 PHP