How to check if a string is one of the known values?

Use the in_array() function.

Manual says:

Searches haystack for needle using loose comparison unless strict is set.

Example:

<?php
$a="abc";

if (in_array($a, array('are','abc','xyz','lmn'))) {
    echo "Got abc";
}
?>

Leave a Comment