Testing For The Existence Of A Key In An Array

<?phpphp
$countries = array('Germany' => 'German', 'France' => 'French', 'Spain' => 'Spanish'); $country = 'asdf'; printf("<p>%s of our visitors are from %s.</p>\n", array_key_exists($country, $countries) ? 'Some' : 'None', $country); ?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.