Organizational Research By

Surprising Reserch Topic

Question:php: array_key_exists-how to check Checks if the given key or index exists in the array

array_key_exists — Checks if the given key or index exists in the array

Ex1  how to use array_key_exists() example

$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
    echo "The 'first' element is in the array";
Ex2  diff between array_key_exists() vs isset()
isset() does not return TRUE for array keys that correspond to a NULL value, while array_key_exists() does.
$search_array = array('first' => null, 'second' => 4);
// returns false
// returns true
array_key_exists('first', $search_array);

asked Sep 13, 2013 in PHP by rajesh
edited Sep 12, 2013
+1 vote

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.