我正在寻找专家来解释为什么 FOREACH 在更新和中断后没有停止?
代码在 3x10 矩阵中找到位置,当它找到它并更新它假设中断并退出但它继续循环的表时......非常非常奇怪。
checkPosUnder('x',array(100000));
function checkPosUnder($userToFill,$underUsers) {
echo "<br>enter func Check on all this users:<br>";
print_r($underUsers);
$newGenUsers = array();
foreach($underUsers as $curuser) {
echo "<br>NEW LOOP<br>";
//$underThisUser
$freeq = $db->prepare("SELECT * FROM tueeunet WHERE username=?");
$freeq->execute(array($curuser));
$freeq->setFetchMode(PDO::FETCH_ASSOC);
$free = $freeq->fetch();
if($free['under1']=='') {
$updateQuery = $db->prepare("UPDATE tueeunet SET under1=? WHERE username=? ");
$updateQuery->execute(array($userToFill,$curuser));
echo "1<br>";
break;
}
elseif($free['under2']=='') {
$updateQuery = $db->prepare("UPDATE tueeunet SET under2=? WHERE username=? ");
$updateQuery->execute(array($userToFill,$curuser));
echo "2<br>";
break;
}
elseif($free['under3']=='') {
$updateQuery = $db->prepare("UPDATE tueeunet SET under3=? WHERE username=? ");
$updateQuery->execute(array($userToFill,$curuser));
echo "3<br>";
break;
}
else {
array_push($newGenUsers, $free['under1'],$free['under2'],$free['under3']);
echo "<br>";
print_r($newGenUsers);
echo "<br>";
checkPosUnder($userToFill,$newGenUsers);
}
}
}