title besides title

 

Thursday, November 8, 2012

PHP : Arrays - [4.11] Checking if a Key Is in an Array

4.11.1 Problem

You want to know if an array contains a certain key.

4.11.2 Solution

Use isset( ):
if (isset($array['key'])) { /* there is a value for 'key' in $array */ }

4.11.3 Discussion

You can check the definedness of an array element just as you'd for any other variable. See the Introduction to Chapter 5 for more information about the truth value of variables.