PHP | ArrayIterator rewind()函数
ArrayIterator::rewind()函数是PHP中的一个内置函数,用于将数组倒回到开头。
句法:
void ArrayIterator::rewind( void )
参数:此函数不接受任何参数。
返回值:此函数不返回任何值。
下面的程序说明了PHP中的 ArrayIterator::rewind()函数:
方案一:
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
方案二:
"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