duannai1883 2013-05-27 15:39
浏览 31
已采纳

我怎么能做这样的事情 - 循环通过一组无限期的数字

I'm trying to loop tru a set of numbers based on the initial number. Tried, but cant see a good way to achieve this. The thing goes inside a while loop.

<?php

$this = 1;

//If 1 then 1,4,7
//If 2 then 3
//If 3 then 10

while ( //mySql while loop ) {
    if ( $this == 1 ) {
        call example() //thrice for 1, 4, 7
    }
}

function example($a) {
    echo $a+10;
}
?>

Here, based on what $this is, I need to call function example. So if $this = 1, I need to call example thrice - $a value 1, 4, 7. If $this = 2 I need to call it once, value 3.

What would be a good way to achieve this?

  • 写回答

2条回答 默认 最新

  • dongrouyuan5685 2013-05-27 15:45
    关注

    Try this:

    <?php 
    
    $this = 1;
    
    $groups = array(
        1 => array(1,4,7),
        2 => array(3),
        3 => array(10) 
    );
    
    foreach($groups[$this] as $value)
       example($value);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动