- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在开发一个项目,生成随机 PIN 码。最初,每个 PIN 码都以 4 位数字开头,即 2345、5456 等。然而,我试图做到这一点,如果使用了所有 4 位数字引脚,则它会增加到 5 位数字,然后是 6 位等等。本质上,这样您就不会用完!
我正在使用 laravel 并创建了一个特征:
<?php
namespace App\Traits;
use App\Models\Quiz;
trait QuizPinTrait
{
private $pin = null;
private $min, $max;
private function setup()
{
$this->min = 1111;
$this->max = 9999;
$this->pin = mt_rand($this->min, $this->max);
}
public function generate()
{
$this->setup();
if ($this->checkNotInUse()) {
return $this->pin;
}
return false;
}
private function checkNotInUse()
{
$inUse = Quiz::where('pin', $this->pin)->count();
if (!$inUse || $inUse == 0) {
return true;
} else {
// stuck here...
}
}
}
我首先考虑将 1 附加到最小值,将 9 附加到最大值,但我不确定如何为此制定有效的解决方案。
最佳答案
您可以创建一个整数数组,[1111,...,9999]
,并根据正在使用的 PIN 数组进行比较,以获取可用的 PIN。
$isUse = Quiz:all()->pluck('pin');
$min = 1111;
$max = 9999;
$allPins = range($min,$max);
$notInUse = array_diff($allPins, $inUse);
// laravel one liner
$notInUse = collect(Quiz:all()->pluck('pin'))->diff(range($min,$max));
然后当当前范围没有更多可用时:
$min = $max+1;
$max *= 10;
关于php - 如何在 PHP 中创建逐渐增加的 PIN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48374626/
我想要一个可以逐渐将页面底部的不透明度从 0 更改为 1 的函数。 我在元素的顶部使用了类似的功能,但我使用的不是淡入,而是淡出。创建它相当容易,但在页面底部使用设置的阈值淡入是一场噩梦。 经过研究,
li 状态是关闭和打开。 闭合:颜色为黑色(没有光照,相互折叠)。 打开:颜色为红色(有光,全视野)。 我希望颜色从两个元素之间的点开始淡化,以表明阴影从轴心开始,直到它们关闭。 $('button'
我的问题很简单: 1)我有一个扩展 JFrame 的主类。 2)该类内部有一个 JPanel,其顶部有一个 BufferedImage。 3)最后还有一个 JButton,我称之为“Fire”..这就
我有这个立方体,我想在延迟 3000 后将其转换为不同的 X 和 Y 点。我无法理解如何在 jQuery 的帮助下做到这一点。这是一个JS Fiddle .下面是代码。 JS // code for
我们如何向背景图像添加黑色阴影,阴影从不透明度 1 开始逐渐降低到不透明度 0,在图像的所有 4 个边上? (至少 50 像素值的“降低阴影不透明度”。box-shadow 仅提供少量不透明度逐渐下降
我是一名优秀的程序员,十分优秀!