How to get a random value from 1~N but excluding several specific values in PHP?

前端 未结 7 2025
不知归路
不知归路 2020-12-10 06:56

rand(1,N) but excluding array(a,b,c,..),

is there already a built-in function that I don\'t know or do I have to implement it myself(how?)

7条回答
  •  萌比男神i
    2020-12-10 07:21

    This is the fastest & best performance way to do it :

    $all =  range($Min,$Max);
    $diff = array_diff($all,$Exclude);
    shuffle($diff );
    $data = array_slice($diff,0,$quantity);
    

提交回复
热议问题