dongwen4630 2016-03-27 14:37
浏览 63
已采纳

数组范围如何使用for循环?

So I'm trying to make a range. Then make this array a range of 1,2,3,4. It will use the numbers 1-4., but I would like to shuffle those numbers for example:2,4,1,3. I'm getting stuck on the array range so far in php.

$range = range(1, 4)
$numbers = array($range);
$totalElements = count( $numbers );

for ( $i=0; $i < $totalElements; $i++ ) {
echo $numbers[$i];
if ( $i < $totalElements -1 ) echo ", ";
  • 写回答

2条回答 默认 最新

  • douxian6086 2016-03-27 14:40
    关注
    <?php
    $numbers = range(1, 4);
    shuffle($numbers);
    foreach ($numbers as $number) {
        echo "$number ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 linux的gcc命令报错
  • ¥20 如何再GIS用海岸线建立缓冲区
  • ¥15 codeblock遇到问题了,求帮助😭
  • ¥15 Qt6.8.0加载网页MSVC2022
  • ¥15 360浏览器m2的这个值
  • ¥15 国内有哪些厂商做automlops的?
  • ¥15 skynet pb mysql
  • ¥15 笔记本外接显示器分辨率太低各种方法都用过了调不高
  • ¥15 Redstone R0697-F00 D2020 交换机 OS
  • ¥50 H5+js 动态数字画廊怎么做?