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 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM