I need to check to make sure a variable equals either 5, 10, 50 or 100. If it doesn’t then I want to set it to 5. Can someone tell me what’s wrong with this IF statement?
if (isset($_REQUEST['number']) && $_REQUEST['number'] !== "5" || $_REQUEST['number'] !== "10" || $_REQUEST['number'] !== "50" || $_REQUEST['number'] !== "100") {
$number = 5;
} else {
$number = $_REQUEST['number'];
}
You need to break up your logic to overcome operator precedence. When in doubt, use parenthesis.
I also inverted the logic. It reads more naturally.
While the above works, you could also streamline it with something like
in_array().