Determining Whether an Element Is in an Array : in_array « Data Structure « PHP






Determining Whether an Element Is in an Array

 
<?php 
$countries = array('Germany' => 'German', 'France' => 'French', 'Spain' => 'Spanish'); 

$language = 'Spanish'; 

printf("<p>%s of our visitors speak %s.</p>\n", in_array($language, $countries) ? 'Some' : 'None', $language); 
$language = 'asdfasd'; 

printf("<p>%s of our visitors speak %s.</p>\n", in_array($language, $countries) ? 'Some' : 'None', $language); 


?>
  
  








Related examples in the same category

1.Checking for an element with a particular value
2.in_array( ) function return true if an array contains a specific value
3.in_array() function is a control statement.
4.Locating Array Elements