PHP code example of pangongzi / algorithm

1. Go to this page and download the library: Download pangongzi/algorithm 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/ */

    

pangongzi / algorithm example snippets



angongzi\Algorithm\Snowflake\SnowflakeService;
$snowflake = new SnowflakeService(1); // 传入机器ID


$id = $snowflake->generate();
echo "生成的唯一ID: " . $id . PHP_EOL;
// int(546849135915962368)


$encodedId = SnowflakeService::encode($id);
echo "Base62 编码后的ID: " . $encodedId . PHP_EOL;
// string(10) "eOZdhSEnw0"