Multiple comparison operators for one variable?
php
Solution
As simple as:
if ($color == 'blue' || $color == 'red' || $color == 'green') {
//do something
}
There are several other options. Using `switch` operator:
switch ($color) {
case 'blue':
case 'red':
case 'green':
//do something
}
Or more complex using `in_array` function:
$colors = array('blue', 'red', 'green');
if (in_array($color, $colors)) {
//do something
}
Problem
I need to do multiple checks for a variable. I've seen an "Equals" example, here: w3schools. But they are two different variables. Right now I have: ``` if ($color == 'blue') { //do something } ``` But I need to to multiple checks for $color. Eg if it equals red or green too. How is this written?