[thelist] OR statement too true in PHP

Richard Harb rharb at earthling.net
Sun Mar 28 16:37:31 CST 2004


Monday, March 29, 2004, 12:16:29 AM, you wrote:

> Any idea why this statement evaluates to TRUE when $_POST[DisplayPhone]
> is 9876543210 ?

>   if (($_POST[DisplayPhone] == 0) OR ($_POST[DisplayPhone] == "") OR
> is_null($_POST[DisplayPhone]))

first of all: DisplayPhone is used as a defined value
If you want to check whether a member of the $_POST array has some
value I'd recommend using $_POST['DisplayPhone']

actually your line could read:
if (empty($_POST['DisplayPhone'])) {
  echo 'No number';
}

check http://php.net/
--> "", 0, "0", NULL, FALSE, array(), var $var;, and objects with
empty properties, are all considered empty.

Richard



More information about the thelist mailing list