Find a needle in a haystack with PHP in_array


Want to see if a single item is in an array in PHP? Use in_array. For example, you have an array of colors and you want to find if red exists. Try this…

$array = array(red, blue, green); 

if (in_array("red", $array)) {
    echo "has red";
}

Leave a Reply

Your email address will not be published. Required fields are marked *