note 48645 added to control-structures.switch

From: Date: Mon, 03 Jan 2005 04:46:56 +0000
Subject: note 48645 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-82631@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48645 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48645&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48645&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48645&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48645&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48645&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48645&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48645&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82631) next »