Home  >  Article  >  Backend Development  >  Analysis of the two process control instructions break and continue in PHP_PHP tutorial

Analysis of the two process control instructions break and continue in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:19:48861browse

Analysis of the two process control instructions break and continue in PHP

<?php
$arr = array(
	&#39;a&#39; => &#39;0a0&#39;,
	&#39;b&#39; => &#39;0b0&#39;,
	&#39;c&#39; => &#39;0c0&#39;,
	&#39;d&#39; => &#39;0d0&#39;,
	&#39;e&#39; => &#39;0e0&#39;,
);
//********break********//
//用来跳出目前执行的循环,并不再继续执行循环了。 
foreach($arr as $k => $v){
	if($k == &#39;c&#39;){ 
		break;
	}
	$arr2[$k] = $v;
}
var_dump($arr2);
/*
array (size=2)
  &#39;a&#39; => string &#39;0a0&#39; (length=3)
  &#39;b&#39; => string &#39;0b0&#39; (length=3)
*/

//********continue********//
//立即停止目前执行循环,并回到循环的条件判断处,继续下一个循环。 
foreach($arr as $k => $v){
	if($k == &#39;c&#39;){ //忽略对这一项的处理
		continue;
	}
	$arr3[$k] = $v;
}
var_dump($arr3);
/*
array (size=4)
  &#39;a&#39; => string &#39;0a0&#39; (length=3)
  &#39;b&#39; => string &#39;0b0&#39; (length=3)
  &#39;d&#39; => string &#39;0d0&#39; (length=3)
  &#39;e&#39; => string &#39;0e0&#39; (length=3)
*/

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/871183.htmlTechArticleAnalysis of the two process control instructions break and continue in PHP 0a0,b => 0b0,c => 0c0,d => 0d0,e => 0e0,);//********break********////Used to jump out of the currently executing loop and no longer continue to execute the loop...
Statement:
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