在php中停止循环(中断并继续不为我工作)

时间:2013-11-14 10:20:56

标签: php if-statement while-loop

我的php中有一些循环系列示例

// select statement

while (gyu_fetch($acaYear_results)) {
 $Year = gyu_get_col($Year_results,0);
          $page->main .= '<option value="'.$Year.'"';
          if ($Year!="" and $Year==$Year) { $page->main .= ' selected="selected"'; }
          $page->main .= '>'.$Year.'</option>';

        }

//选择陈述

 while(gyu_fetch($domain_results)) {
                    $row = gyu_get_col($results,0);
    $page->main .= '<option value="'.$row.'">'.$row.'</option>';            
            }


  if ($tui_domain != $tui_domain_old and $tui_domain_old != 'REiOl7')
      {
        $page->main .= '<tr><td colspan="4" style="background-color:#DDDDDD;">&nbsp;</td></tr>';
      }

在我所有的while循环和foreach循环中,我使用了break;continue;但是当我在select语句中使用它们时。 会发生什么是我的网页不会完全呈现,因为它只会影响其他if语句。

我想知道他们是否有其他方法可以阻止whileif语句反复循环,但不会影响可能正在使用它的页面的任何元素

   while(gyu_fetch($domain_results)) {
                        $row = gyu_get_col($results,0);
         break;         
                }
$page->main .='"'.$row.'"';

在该示例中虽然我已经结束了当前while结构的执行,但这会影响正在使用的'"'.$row.'"'吗?

1 个答案:

答案 0 :(得分:0)

你不能在while循环之外使用$row,因为它是在循环内声明的,因此它是本地的。尝试在循环($row='';)之前初始化它。

更多关于variable scope in PHP