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?
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 ] )
Example
<?php$mylist = array("Mac", "Windows", "Android", "Ubuntu");if (in_array("Mac", $mylist)) { echo "Yes";}else{echo "No";}?>
<?php$mylist = array("Mac", "Windows", "Android", "Ubuntu");if (in_array("Mac", $mylist)) { echo "Yes";}else{
echo "No";
}
?>