How can I skip the output

I want to skip number 10 so that I only have numbers from 15 to 5 without displaying the number 10.

    <?php

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

    ?>
+4
source share
5 answers

Add a condition ifto ignore $xwhen it is 10:

<?php

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

?>`
+4
source
<?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>';
    }
?>
+4
source

All other messages are true, but as you study, you must learn without using shorthand, as it is sometimes difficult to read.

Not everyone uses the abbreviated form, and in most cases the coding standard is used. In particular, we do not use abbreviations.

Example:

<?php

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

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

Another way without test:

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

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

All Articles