简体   繁体   English

我怎样才能跳过输出结果

[英]how can i skip an output result

I want to skip the number 10 so that i only have numbers from 15 to 5 without outputting number 10. 我想跳过数字10,这样我只有15到5的数字,而不输出数字10。

    <?php

    $x = 15;
    while($x >=5) {
    echo "$x <br>"; 
    $x--;
    } 

    ?>
<?php
    for($i=15;$i>=5;$i--){
       if($i == 10) continue;
       echo $i . '<br>';
    }
?>

or 要么

<?php
    for($i=15;$i>=5;$i--){
       if($i != 10) echo $i . '<br>';
    }
?>

Add an if condition to ignore $x when it is equal to 10: 添加if条件,当它等于10时忽略$x

<?php

    $x = 15;
    while($x >=5 ) {
        if($x != 10) echo $x . "<br>"; 
        $x--;
    } 

?>`

All the other posts are correct, but since you're learning, you should really learn without using shorthand, as it can sometimes be difficult to read. 所有其他帖子都是正确的,但是既然你正在学习,你应该在不使用速记的情况下学习,因为它有时候很难阅读。

Not everyone uses shorthand, and in most practices a coding standard is used. 不是每个人都使用速记,并且在大多数实践中使用编码标准。 Ours in particular doesn't use shorthand. 我们特别不使用速记。

Example: 例:

<?php

$x = 15;
while($x >=5 ) {
    if($x != 10){
        echo $x . "<br />"; 
    }
    $x--;
} 

?>
 $num = 15;
   while($num >=5 ) {
    if($num != 10) echo $num . "\n"; 
    $num--;
  } 

An other way without test: 没有测试的另一种方式:

$a = array_merge(range(15,11), range(9,5));

foreach($a as $num)
    echo $num . '<br>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM