Php: check if value exists in array

Trabla: Php: check if value exists in array

Solving:

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

Example:

<?php

$array_of_cities = array( 'London', 'Berlin', 'New York' );

if(   in_array(  'Odessa',  $array_of_cities )    ){
    echo 'City not in array';
}else{
   echo 'Hooray!!! City in array!';
}
 
?>

Official Docs: http://php.net/manual/en/function.in-array.php


No comments:

Post a Comment