在下面的代码中,如果
$getd[0]
为空,我想跳到下一条记录。foreach ($arr as $a1) {
$getd = explode(',' ,$a1);
$b1 = $getd[0];
}
我该如何实现它?
$getd[0]
不为空时才会执行某些操作。foreach ($arr as $a1) {
$getd=explode(",",$a1);
if (!empty($getd[0])) {
$b1=$getd[0];
}
}
或者,我们可以使用 continue
关键字,在$getd[0]
为空时跳过到下一次迭代。
foreach ($arr as $a1) {
$getd=explode(",",$a1);
if (empty($getd[0])) {
continue;
}
$b1=$getd[0];
}
使用continue
语句,它将跳过当前迭代并进入下一次循环。
foreach ($arr as $a1){
$getd=explode(",",$a1);
if(empty($getd[0])){
continue;
}
$b1=$getd[0];
}