下面系列中的第二个 if 语句不断返回 true 并打印出即使estimateId不是数组中的唯一项。我该如何纠正?
目标是确保在下面的系列中始终只有一个 if 语句匹配。
例如,现在第二个 if 在第三个 if 的情况下返回 true。这不应该发生。
https://localhost/data.php?estimateId=1001
https://localhost/data.php?estimateId=1001&proposalsFilter=all
.
<?php
# estimates/active/
if (in_array($_GET["estimatesFilter"], $_GET)) {
print_r('estimatesFilter: ' . $_GET["estimatesFilter"] . ' url parameter(s) was passed.');
print_r("<br>");
}
# This if keeps returning true even if estimateId is not the only item in the array?
# estimates/1001/
if (in_array($_GET["estimateId"], $_GET)) {
print_r('estimateId: ' . $_GET["estimateId"] . ' url parameter(s) was passed.');
print_r("<br>");
}
# estimates/1001/proposals/
if (in_array($_GET["estimateId"], $_GET) && in_array($_GET["proposalsFilter"], $_GET)) {
print_r('estimateId: ' . $_GET["estimateId"] . ' & ' . 'proposalsFilter: ' . $_GET["proposalsFilter"] . ' url parameter(s) was passed.');
print_r("<br>");
}
# estimates/1001/proposals/3001/
if (in_array($_GET["estimateId"], $_GET) && in_array($_GET["proposalId"], $_GET)) {
print_r('estimateId: ' . $_GET["estimateId"] . ' & ' . 'proposalId: ' . $_GET["proposalId"] . ' url parameter(s) was passed.');
print_r("<br>");
}
# estimates/1001/contracts/
if (in_array($_GET["estimateId"], $_GET) && in_array($_GET["contractsFilter"], $_GET)) {
print_r('estimateId: ' . $_GET["estimateId"] . ' & ' . 'contractsFilter: ' . $_GET["contractsFilter"] . ' url parameter(s) was passed.');
print_r("<br>");
}
# estimates/1001/contracts/3001/
if (in_array($_GET["estimateId"], $_GET) && in_array($_GET["contractId"], $_GET)) {
print_r('estimateId: ' . $_GET["estimateId"] . ' & ' . 'contractId: ' . $_GET["contractId"] . ' url parameter(s) was passed.');
print_r("<br>");
}
绝地无双
千万里不及你