shortdark / lightswitch
Lightswitch Composer 包生成自定义的随机数字数组。
0.0.20
2018-11-26 10:00 UTC
Requires
- php: >=7.0.0
README
当你指定最低整数、最高整数和所需整数的数量时,Lightswitch 创建一个唯一的整数数组。
安装
使用以下命令安装最新版本
$ composer require shortdark/lightswitch
基本用法
<?php require_once 'vendor/autoload.php'; $test = new Shortdark\Lightswitch(); // All you can do at the moment is to press the lightswitch // press($lowest_integer, $highest_integer, $how_many_integers) $result = $test->press(1,49,7); // You can also specify two different rules, for example, // 5 integers between 1 and 49, then 2 integers between 1 and 9 $result = $test->press(1,49,5,1,9,2); // The result will be an array of integers var_dump($result);
在 Laravel 控制器中的基本用法
<?php use App\Http\Controllers\Controller; use Shortdark\Lightswitch; class MyController extends Controller { public function index(Lightswitch $light) { $result = $light->press(1,49,5,1,9,2); return view('index', compact('result')); } }
然后,由于 $result 是一个数组,你可以在 index.blade.php 中使用以下类似的方法来获取数组的表示。
{{ json_encode($result) }}
作者
Neil Ludlow - neil@shortdark.net - https://twitter.com/shortdark