Swoole\Table::rewind()

将内部指针重置到表的第一个元素

首字母:S

函数名称:Swoole\Table::rewind()

函数描述:该函数用于将内部指针重置到表的第一个元素。

参数:无

返回值:无

使用版本:Swoole v4.4.0+

示例:

column('id', Swoole\Table::TYPE_INT);
$table->column('name', Swoole\Table::TYPE_STRING, 64);
$table->create();
$table->set(1, ['id' => 1, 'name' => 'Alice']);
$table->set(2, ['id' => 2, 'name' => 'Bob']);
$table->set(3, ['id' => 3, 'name' => 'Charlie']);
// 重置指针到第一个元素
$table->rewind();
// 遍历并输出所有元素
while ($row = $table->current()) {
 echo "ID: " . $row['id'] . ", Name: " . $row['name'] . "\n";
 $table->next();
}
?>

以上示例代码创建了一个包含id和name两个列的表,并插入了三个元素。然后使用rewind()函数将内部指针重置到第一个元素,再使用current()函数获取当前元素的值,并使用next()函数将指针移动到下一个元素。循环遍历输出所有元素的id和name值。

注意:rewind()函数只在Swoole v4.4.0及以上版本中可用。

同首字母函数