php循環html
發布時間: 2025-05-06 06:31:16
❶ php中在循環外部如何強制結束循環
PHP中用foreach()循環中,想要在循環的時候,當滿足某個條件時,想要跳出本次循環繼續執行下次循環,或者滿足某個條件的時候,終止foreach()循環,分別會用到:continue
與
break。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$arr
=
array('a','b','c','d','e');
$html
=
'';
foreach($arr
as
$key
=>
$value){
if($value=='b'){
$html
.=
$value;
continue;
//
當
$value為b時,跳出本次循環
}
if($value=='c'){
$html
.=
$value;
break;
//
當
$value為c時,終止循環
}
$html
.=
$value;
}
echo
$html;
//
輸出:
abc
熱點內容