douzhizao0270 2012-12-31 12:48
浏览 5
已采纳

if ... else发布:删除匹配的变量

i am new to coding and can't establish idea for easy logic..
ok, I have written a code firstly have a look:

<?php
    function month_ana($mna){
        $c_mna = strlen($mna);
        echo "Let's Analysis <b>$mna</b> <br> Total Charectars: $c_mna <br>";
    }
    $go[0] = "January";
    $go[1] = "February";
    $go[2] = "March";
    $go[3] = "April";
    $go[4] = "May";
    $go[5] = "June";
    $go[6] = "July";
    $go[7] = "August";
    $go[8] = "September";
    $go[9] = "October";
    $go[10] = "November";
    $go[11] = "December";
    $fo = "October";
    $i = 0;
    for($i=0;$i<=11;$i++){
        if ($go[$i]==$fo){
            break;
        } else { 
            month_ana($go[$i]);
        }
    }
?>

what i wanna do is to delete the matched variable so, the function will skip it.
Let's see its output:

Let's Analysis January 
Total Charectars: 7 
Let's Analysis February 
Total Charectars: 8 
Let's Analysis March 
Total Charectars: 5 
Let's Analysis April 
Total Charectars: 5 
Let's Analysis May 
Total Charectars: 3 
Let's Analysis June 
Total Charectars: 4 
Let's Analysis July 
Total Charectars: 4 
Let's Analysis August 
Total Charectars: 6 
Let's Analysis September 
Total Charectars: 9 

but problem is i have used break(); statement so it stop working when variables matched in October, but i wish that, this will skip the matched variable not stop here, so in this case it should skip October and then start calculating again from November and continue. I hope u understand the problem. Any ideas?

If you think you should refer me some articles then please do, because i am very keen to learn PHP programming. Thanks

  • 写回答

3条回答 默认 最新

  • drblhw5731 2012-12-31 12:51
    关注

    try continue;

    var $go = array('January', 'February', 'March', ...);
    
    foreach ($go as $month) {
       if ($month == $fo){
          continue;
       } 
       echo $month . '<br />';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改