lamansky/secure-shuffle
最新稳定版本:1.0.0
Composer 安装命令:
composer require lamansky/secure-shuffle
包简介
Reorders array elements using cryptographically-secure randomization.
README 文档
README
A PHP library for reordering array elements using cryptographically-secure randomization.
Installation
With Composer installed on your computer and initialized for your project, run this command in your project’s root directory:
composer require lamansky/secure-shuffle
Requires PHP 7.1 or above.
Examples
The library makes 4 functions available for import. Here is an example with all four functions in use:
<?php use function Lamansky\SecureShuffle\shuffle; use function Lamansky\SecureShuffle\shuffle_assoc; use function Lamansky\SecureShuffle\shuffled; use function Lamansky\SecureShuffle\shuffled_assoc; // Shuffles an indexed array in-place. // Note that we are using the imported shuffle() function, // not the built-in \shuffle() function. $arr = [1, 2, 3, 4, 5]; shuffle($arr); print_r($arr); // Array ( [0] => 4 [1] => 5 [2] => 2 [3] => 1 [4] => 3 ) // Shuffles an associative array in-place. $arr = ['a' => 1, 'b' => 2, 'c' => 3]; shuffle_assoc($arr); print_r($arr); // Array ( [b] => 2 [a] => 1 [c] => 3 ) // Creates a shuffled copy of an indexed array. $orig = [1, 2, 3, 4, 5]; $copy = shuffled($orig); print_r($orig); // Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) print_r($copy); // Array ( [0] => 5 [1] => 2 [2] => 4 [3] => 3 [4] => 1 ) // Creates a shuffled copy of an associative array. $orig = ['a' => 1, 'b' => 2, 'c' => 3]; $copy = shuffled_assoc($orig); print_r($orig); // Array ( [a] => 1 [b] => 2 [c] => 3 ) print_r($copy); // Array ( [c] => 3 [a] => 1 [b] => 2 )
统计信息
- 总下载量: 15.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-17