start page | rating of books | rating of authors | reviews | copyrights

Book HomePHP CookbookSearch this book

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.

4.11.4. See Also

Documentation on isset( ) at http://www.php.net/isset.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.