Swoole\Table::__construct

Notice: the documentation is suitable for PHP extension swoole until v4.7.1, we only support PHP extension openswoole from v4.7.1

Declaration

<?php
Swoole\Table::__construct (int $table_size [, $conflict_proportion = 0.2 ])

Parameters

table_size

The number of rows of the table.

conflict_proportion

The percentage of confliction is allowed in the hashmap.

Return

Description

Create a Table (hashmap) with defined rows.

For performance reason, from v4.7.0, you can't use object of type Swoole\Table as array.

Example

<?php

$table = new Swoole\Table(1024);
$table->column('name', Swoole\Table::TYPE_STRING, 64);
$table->column('id', Swoole\Table::TYPE_INT, 4);       //1,2,4,8
$table->column('num', Swoole\Table::TYPE_FLOAT);
$table->create();

$table->set('a', array('id' => 1, 'name' => 'swoole-co-uk', 'num' => 3.1415));
$table->set('b', array('id' => 2, 'name' => "swoole-uk", 'num' => 3.1415));
$table->set('[email protected]', array('id' => 3, 'name' => 'swoole', 'num' => 3.1415));

var_dump($table->get('a'));
var_dump($table->get('b', 'name'));