小编Nic*_*lla的帖子

每次在PHP中只有5个数字

我想在数组中添加5个随机数,但每个数字必须不同.这是我到目前为止所拥有的......

$col_B = array();

for ($i=1; $i < 6; $i++) { 
    $rand = $col_ranges['B'][rand ( 0 , 14 )]; // calls to an array of numbers
    if(!in_array($rand, $col_B)){
        $col_B[] = $rand;   
    }
    else{ $i - 1;}

}
echo implode($col_B, '<br>');
Run Code Online (Sandbox Code Playgroud)

php arrays random loops

-1
推荐指数
1
解决办法
78
查看次数

标签 统计

arrays ×1

loops ×1

php ×1

random ×1