note 48645 rejected from control-structures.switch by cece

From: Date: Mon, 03 Jan 2005 07:51:53 +0000
Subject: note 48645 rejected from control-structures.switch by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82633@lists.php.net to get a copy of this message
Note Submitter: c dot hawkins at swavideo dot com ---- Got a quick question... I am new to this and was playing around with a script to collect a phone (just for testing and learning). I wanted to use the switch conditional to validate the string passed from the HTML form. My code is: switch ($phone){ case empty($phone): print("The Number is Empty"); break; case !is_numeric($phone): print("You must enter a numerical value"); break; case strlen($phone) != 9: print("You Must enter at least 9 numbers"); break; default: print("Thank you for your number - we will call you soon."); break; } The problem is the first case - If the field (string) was left empty is should run the statment print("The Number is Empty"); however it doesnt... it just goes the default. The other two funtions work fine. Is there something I am missing with the empty() function in switch? I could use case "" but I was wondering firt if I am doing something wrong. Thanks, Chris

« previous php.notes (#82633) next »