drbz99867 2018-06-02 21:33
浏览 203
已采纳

数组范围仅在选定的数字PHP范围内

I am a a 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.

  • 写回答

1条回答 默认 最新

  • dongmeng4742 2018-06-02 21:46
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?