PHP 从 rand() 函数中排除数字 [英] PHP excluding numbers from rand() function

查看:52
本文介绍了PHP 从 rand() 函数中排除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了 rand() 3 次,我想从函数的可能性中排除前两个结果.就像它命中 1 和 5 一样,我希望下一个 rand() 从其范围中排除 1 和 5.我该怎么做?

I'm running rand() 3 times, and I want to exclude the first two results from the possibilities of the function. Like if it hit 1 and 5, I want the next rand() to exclude 1 and 5 from its range. How would I do this?

推荐答案

怎么样:

do {   
    $rand_number = rand();

}while(in_array($rand_number, array(1,5));

这篇关于PHP 从 rand() 函数中排除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆