public function test()
{
$count = [];
$count[] = ['key' => 'name', 'type' => 'string', 'len' => 50];
$count[] = ['key' => 'title', 'type' => 'string', 'len' => 50];
$temp = new swoole_table(1024);
$allType = ['int' => swoole_table::TYPE_INT, 'string' => swoole_table::TYPE_STRING, 'float' => swoole_table::TYPE_FLOAT];
foreach ($count as $row) {
$temp->column($row['key'], $allType[$row['type']], $row['len']);
}
$temp->create();
foreach ([1, 2, 3] as $val) {
$value = ['title' => "这是第{$val}个标题"];
$temp->set($val, $value);
}
foreach ([4, 5, 6] as $val) {
$value = ['name' => "这是第{$val}个名字"];
$temp->set($val, $value);
}
foreach ([7, 8, 9] as $val) {
$value = ['name' => "这是第{$val}个名字", 'title' => "这是第{$val}个标题"];
$temp->set($val, $value);
}
$value = [];
foreach ([1, 2, 3, 4, 5, 6, 7, 8, 9] as $val) {
$value[] = $temp->get($val);
}
print_r($value);
}
美中不足的是还没找到可以遍历所有键值的方法。