Home > Backend Development > PHP Problem > What is the usage of continue in php

What is the usage of continue in php

王林
Release: 2023-03-11 09:26:02
Original
3324 people have browsed it

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;}].

What is the usage of continue in php

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 时的循环
Copy after login

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 时的循环
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template