【发布时间】:2011-08-07 04:04:24
【问题描述】:
在下面的代码中,如果$getd[0]为空,我想去下一条记录。
foreach ($arr as $a1) {
$getd = explode(',' ,$a1);
$b1 = $getd[0];
}
我怎样才能实现它?
【问题讨论】:
在下面的代码中,如果$getd[0]为空,我想去下一条记录。
foreach ($arr as $a1) {
$getd = explode(',' ,$a1);
$b1 = $getd[0];
}
我怎样才能实现它?
【问题讨论】:
我们可以使用 if 语句仅在 $getd[0] 不为空的情况下才导致某些事情发生。
foreach ($arr as $a1) {
$getd=explode(",",$a1);
if (!empty($getd[0])) {
$b1=$getd[0];
}
}
或者,如果$getd[0] 为空,我们可以使用continue 关键字跳到下一次迭代。
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];
}
【讨论】: