English 中文(简体)
离开开关,然后继续 lo
原标题: break from a switch, then continue in a loop

是否可能脱离开关,然后继续停留在路边?

For example:

$numbers= array(1,2,3,4,5,6,7,8,9,0);
$letters = array( a ,  b ,  c ,  d ,  e ,  f ,  g );

foreach($letters as $letter) {
    foreach($numbers as $number) {
        switch($letter) {
           case  d :
               // So here I want to  break;  out of the switch,  break;  out of the
               // $numbers loop, and then  continue;  in the $letters loop.
               break;
        }
    }

    // Stuff that should be done if the  letter  is not  d .

}

Can this be done, and what would the syntax be?

最佳回答
问题回答

http://code>break, 使用continue 2

我知道这是一个严重的 ne,但......由于我从谷歌图一来到这里,使其他人感到困惑。

如果他打算从开关中脱出来,而只是结束序号,那么<代码>第2号;将罚款。 <代码>continue 2;将仅继续使用编号,并通过该编号保持编号为continue<>。 d 每次。

Ergo,正确的答案应当是continue 3;

http://www.php.net/manual/en/control-polis.continue.php#96945"rel=“noreferer” docs中的评论基本上继续到结构的结束,因为(认为与休息一样)的转变是,在接下来的炉.上 lo。

<?php
    echo "Hello, World!<pre>";

$numbers= array(1,2,3,4,5,6,7,8,9,0);
$letters = array( a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i );

$i = 0;
foreach($letters as $letter) {
    ++$i;
    echo $letter . PHP_EOL;
    foreach($numbers as $number) {
        ++$i;
        switch($letter) {
           case  d :
               // So here I want to  break;  out of the switch,  break;  out of the
               // $numbers loop, and then  continue;  in the $letters loop.
              continue 3; // go to the end of this switch, numbers loop iteration, letters loop iteration
            break;
           case  f :
            continue 2; // skip to the end of the switch control AND the current iteration of the number s loop, but still process the letter s loop
            break;
           case  h :
            // would be more appropriate to break the number s loop
            break 2;

        }
        // Still in the number s loop
        echo " $number ";
    }


    // Stuff that should be done if the  letter  is not  d .
    echo " $i " . PHP_EOL;

}

成果:

Hello, World!
a
 1  2  3  4  5  6  7  8  9  0  11 
b
 1  2  3  4  5  6  7  8  9  0  22 
c
 1  2  3  4  5  6  7  8  9  0  33 
d
e
 1  2  3  4  5  6  7  8  9  0  46 
f
 57 
g
 1  2  3  4  5  6  7  8  9  0  68 
h
 70 
i
 1  2  3  4  5  6  7  8  9  0  81 

<代码>continue 2;不仅处理该信的左 lo,而且处理该编号的其余部分(注:$i在f之后加印。 (......)

Hope that helps anyone else that winds up here first.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签