PHP code example of zhujinkui / helper

1. Go to this page and download the library: Download zhujinkui/helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zhujinkui / helper example snippets


// 引入文件
$idWorker = new \think\SnowflakeIdWorker(0, 0);
//获取ID
$id       = $idWorker->nextId();
echo $id . PHP_EOL;


// 引入文件
$idWorker = new \think\SnowflakeIdWorker(0, 0);

//多机部署的情况下 需要指定工作机器的ID 和 数据中心的ID
//每个节点要保持  $workerId 和  $datacenterId 与其他节点不相同
//另 用一个二维的($workerId,$datacenterId)来唯一标示一个机器
$workerId     = 0;
$datacenterId = 0

//实例化对象
$idWorker = new \think\SnowflakeIdWorker($workerId, $datacenterId);
//获取ID
$id = $idWorker->nextId();
echo $id . PHP_EOL;


$idWorker = new \think\SnowflakeIdWorker(0, 0);

for ($i = 0; $i < 100; $i++) {
    $id = $idWorker->nextId();
    echo $id . PHP_EOL;
    echo '<br/>';
}