The continue statement
The PHP continue keyword is used to halt the current iteration of a loop but it does not terminate the loop.
Just like the break statement, the continue statement is situated inside the statement block containing the code that the loop executes, preceded by a conditional test. For the pass encountering continue statement, rest of the loop code is skipped and the next pass starts.
In the following example loop prints the value of array but for which condition becomes true it just skips the code and next value is printed.
<html>
<body>
<?php
$arrayVal = array( 1, 2, 3, 4, 5);
foreach( $arrayVal as $getValue ) {
if( $getValue == 4 )
continue;
echo "Value is $getValue <br />";
}
?>
</body>
</html>
Output :
Value is 1
Value is 2
Value is 3
Value is 5
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning