私は基本的にこれを言う条件を持っています:
タイプが 5 で、ユーザー ステータスがサインインしていないか、履歴カウントが 0 の場合 (または両方が true - ユーザーがサインインしていない AND 履歴カウントが 0) の場合、何かを実行します (この場合、次のループをスキップします)。処理し、次のイテレータにジャンプします)。
私は何か間違ったことをしている。
コードは次のとおりです。
if($row['type'] === 5 && ($_SESSION['appState']['user_state']['status'] <> STATE_SIGNED_IN || $historyRtn[0]['historyCnt'] === 0) ) {
error_log("don't create");
continue;
}
else {
error_log("type: " . $row['type'] . "; appState: " .$_SESSION['appState']['user_state']['status'] . "; historyCount: " . $historyRtn[0]['historyCnt'] );
}
が 5であるコードのすべてのチャンクについて$row['type']
、他の値が何であるかに関係なく、else にヒットしています。これは、else からのエラー ログです。(参考までに、STATE_SIGNED_IN
「サインイン」に設定されています。)
// this one incorrectly hits the else, as appState is not signed in and historyCount is 0
type: 5; appState: recognized unregistered; historyCount: 0
// this one incorrectly hits the else, as appState is signed in, but historyCount is still 0
type: 5; appState: signed in; historyCount: 0
// this one correctly hits the else, as appState is signed in and historyCount is 1
type: 5; appState: signed in; historyCount: 1
3 つの条件すべてが true の場合にのみ else にヒットするように、if ステートメントをどのように表現する必要がありますか? if type is 5 and appState is signed in and historyCount > 0 というステートメントを変更したくありません。これは、else が必要であり (今はテストのために else しかありません)、残りのすべてを移動する必要があるためです。これが内部で実行されているループコードをelseに追加します-if内でループを実行したくない条件を評価できる場合は、continue
処理したくないアイテムのみをスキップするために使用できます。