array_search()

From: Date: Fri, 26 Oct 2001 20:49:11 +0000
Subject: array_search()
Groups: php.general 
Request: Send a blank email to php-general+get-72498@lists.php.net to get a copy of this message
I'm trying to figure out how am I supposed to write this snippet properly: if (($index = array_search($search, array_keys($pages))) !== false) { echo "index: $index\n"; } else { echo "Not found\n"; } When I search for something that I know exists, it returns the $index just fine. However, when I search for something that does not exist, it never tells me 'Not found', instead it just displays a blank index (it looks like $index = "", not false). Should I be checking it against 'false', or against "" ? Using PHP 4.0.7-dev. -- W | I haven't lost my mind; it's backed up on tape somewhere. +-------------------------------------------------------------------- Ashley M. Kirchner <mailto:ashley@pcraft.com> . 303.442.6410 x130 IT Director / SysAdmin / WebSmith . 800.441.3873 x130 Photo Craft Laboratories, Inc. . 3550 Arapahoe Ave. #6 http://www.pcraft.com ..... . . . Boulder, CO 80303, U.S.A.

« previous php.general (#72498) next »