PHP rand()排除某些数字 [英] PHP rand() exclude certain numbers

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

问题描述

我有这个:

<?php  $n = rand(1,1600); echo $n ?>

我想从随机数中排除234、1578、763、1274和其他数字.我该怎么办?

I want to exclude from random numbers let's say 234, 1578 ,763 , 1274 and other numbers. How would I do that?

推荐答案

<?php

while( in_array( ($n = mt_rand(1,1600)), array(234, 1578 ,763 , 1274) ) );

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

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