Home >Backend Development >PHP Problem >What is the usage of continue in php
The usage of continue in php is to terminate a single loop of the loop body, and the code will continue to execute, such as [if($a == 2 {continue;}].
The operating environment of this article: Windows 10 system, PHP 7.3, thinkpad t480 computer.
Let’s first look at the actual usage of continue. The specific code is as follows:
<?php $tmpVar = []; for($a = 1; $a++; $a<10){ if($a == 2){ continue; } array_push($tmpVar, $a); } print_r($tmpVar); //结果如下 array(1, 3,4,5,6,7,8,9); //这里的continue 跳出$a == 2 时的循环
The continue command will terminate the single loop of the loop body, and the code will continue to execute.
continue and continue1 are the same, continue2 refers to jumping out of the loop twice, and the code continues Execute below.
For example:
<?php $tmpVar = []; for($a = 1; $a++; $a<10){ if($a == 2){ continue; } array_push($tmpVar, $a); } print_r($tmpVar); //结果如下 array(1, 3,4,5,6,7,8,9); //这里的continue 跳出$a == 2 时的循环
Related video tutorial sharing: php video tutorial
The above is the detailed content of What is the usage of continue in php. For more information, please follow other related articles on the PHP Chinese website!