Home  >  Article  >  Backend Development  >  PHP中break及continue两个流程控制指令解析

PHP中break及continue两个流程控制指令解析

WBOY
WBOYOriginal
2016-06-23 13:51:03795browse

<?php $arr = array(	'a' => '0a0',	'b' => '0b0',	'c' => '0c0',	'd' => '0d0',	'e' => '0e0',);//********break********////用来跳出目前执行的循环,并不再继续执行循环了。 foreach($arr as $k => $v){	if($k == 'c'){ 		break;	}	$arr2[$k] = $v;}var_dump($arr2);/*array (size=2)  'a' => string '0a0' (length=3)  'b' => string '0b0' (length=3)*///********continue********////立即停止目前执行循环,并回到循环的条件判断处,继续下一个循环。 foreach($arr as $k => $v){	if($k == 'c'){ //忽略对这一项的处理		continue;	}	$arr3[$k] = $v;}var_dump($arr3);/*array (size=4)  'a' => string '0a0' (length=3)  'b' => string '0b0' (length=3)  'd' => string '0d0' (length=3)  'e' => string '0e0' (length=3)*/?>

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