Derfder Derfder - 1 year ago 86
PHP Question

Check if a key exists and get a corresponding value from an array in PHP

Any idea how to check if a key exists and if yes, then get the value of this key from an array in php.


I have this array:

$things = array(
'AA' => 'American history',
'AB' => 'American cooking'

$key_to_check = 'AB';

Now, I need to check if $key_to_check exists and if it does, get a coresponding value which in this case will be American cooking

Answer Source
    echo $things[$key_to_check];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download