简体   繁体   中英

Array range within a range of only chosen numbers PHP

I am aa beginner and i made this:

<?php

$numbers = range(1, 100);

shuffle($numbers);
foreach ($numbers as $number) {
    echo $number . " ";


}

?>

I thought i could make it work with the out commented code but i don't know what to do anymore after searching so much online, i thought i could copy it(for) and make it work but it copied the same shuffle range instead of separate shuffle numbers.

I want the range from 1 until 100 with numbers only between 1 and 6. That's it.

Thanks for your time.

Simple loop adding 100 random values to array:

$random_ints = [];
while (count($random_ints) < 100) {
    $random_ints[] = random_int(1, 6);
    // or 
    // $random_ints[] = mt_rand(1, 6);
}
echo implode($random_ints);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM