+2 votes
in Programming Languages by (14.2k points)

In python, if we have a list of values, we can check whether or not a particular value is present in the list using 'in' [e.g. if val in list]. Is there an equivalent syntax in PHP?

1 Answer

0 votes
by (4.6k points)

Yes, there is an equivalent syntax in PHP. You can use in_array

Syntax is -

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )


$mylist = array("Mac", "Windows", "Android", "Ubuntu");
if (in_array("Mac", $mylist)) {
    echo "Yes";

echo "No";