ArrayIterator::rewind()函数是PHP中的内置函数,用于将阵列倒回开始。
用法:
void ArrayIterator::rewind( void )
参数:该函数不接受任何参数。
返回值:该函数不返回任何值。
以下示例程序旨在说明PHP中的ArrayIterator::rewind()函数:
示例1:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array(
"a" => 4,
"b" => 2,
"g" => 8,
"d" => 6,
"e" => 1,
"f" => 9
)
);
// Move to last position
$arrItr->seek(5);
// Display the next value
var_dump($arrItr->next());
// Move to start position
$arrItr->rewind();
// Display the current element
echo $arrItr->current();
?>
输出:
NULL 4
示例2:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array(
"b" => "for",
"a" => "Geeks",
"e" => "Science",
"c" => "Geeks",
"f" => "Portal",
"d" => "Computer"
)
);
// Check the validity of ArrayIterator
while($arrItr->valid()) {
$arrItr->next();
}
// Move to start position
$arrItr->rewind();
// Display the current element
echo $arrItr->current();
?>
输出:
for
参考: https://www.php.net/manual/en/arrayiterator.rewind.php
相关用法
- PHP rewind( )用法及代码示例
- PHP SimpleXMLIterator rewind()用法及代码示例
- PHP SplFixedArray rewind()用法及代码示例
- PHP SplFileObject rewind()用法及代码示例
- PHP SplDoublyLinkedList rewind()用法及代码示例
- PHP FilesystemIterator rewind()用法及代码示例
- PHP CachingIterator rewind()用法及代码示例
- PHP SplObjectStorage rewind()用法及代码示例
- PHP DirectoryIterator rewind()用法及代码示例
- PHP AppendIterator rewind()用法及代码示例
- PHP ArrayIterator next()用法及代码示例
- PHP ArrayIterator key()用法及代码示例
- PHP ArrayIterator __construct()用法及代码示例
- PHP ArrayIterator seek()用法及代码示例
- PHP ArrayIterator asort()用法及代码示例
注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | ArrayIterator rewind() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。