SplObjectStorage::current()函数是PHP中的内置函数,用于获取存储的当前条目。
用法:
object SplObjectStorage::current()
参数:该函数不接受任何参数。
返回值:此函数返回当前存储的对象。
以下程序说明了PHP中的SplObjectStorage::current()函数:
示例1:
<?php
// Declare an SplObjectStorage
$storage = new SplObjectStorage();
// Declare new object
$obj = new StdClass;
// Use attach() function to add object
$storage->attach($obj, "GeeksforGeeks");
$storage->rewind();
// Use current() function to get
// the current object
$object = $storage->current();
$data = $storage->getInfo();
var_dump($object);
var_dump($data);
?>
输出:
object(stdClass)#2 (0) { } string(13) "GeeksforGeeks"
示例2:
<?php
// Declare an SplObjectStorage
$str = new SplObjectStorage();
// Declare new object
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$obj4 = new StdClass;
// Use attach() function to add object
$str->attach($obj1, "GeeksforGeeks");
$str->attach($obj2, "GFG");
$str->attach($obj3, "Geeks");
$str->attach($obj4, "PHP");
$str->rewind();
while($str->valid()) {
$index = $str->key();
// Use current() function to get
// the current object
$object = current($str);
$data = $str->getInfo();
var_dump($object);
var_dump($data);
$str->next();
}
?>
输出:
bool(false) string(13) "GeeksforGeeks" bool(false) string(3) "GFG" bool(false) string(5) "Geeks" bool(false) string(3) "PHP"
参考: https://www.php.net/manual/en/splobjectstorage.current.php
相关用法
- PHP SplObjectStorage key()用法及代码示例
- PHP SplObjectStorage next()用法及代码示例
- PHP SplObjectStorage contains()用法及代码示例
- PHP SplObjectStorage getinfo()用法及代码示例
- PHP SplObjectStorage detach()用法及代码示例
- PHP SplObjectStorage offsetExists()用法及代码示例
- PHP SplObjectStorage offsetSet()用法及代码示例
- PHP SplObjectStorage addAll()用法及代码示例
- PHP SplObjectStorage count()用法及代码示例
- PHP SplObjectStorage valid()用法及代码示例
- PHP SplObjectStorage attach()用法及代码示例
- PHP SplObjectStorage rewind()用法及代码示例
- PHP SplObjectStorage serialize()用法及代码示例
- PHP SplObjectStorage setInfo()用法及代码示例
- PHP SplObjectStorage unserialize()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplObjectStorage current() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。