Jump to content

(!$var)


niche
 Share

Recommended Posts

Please, what does "(!$var)" mean?I'm pretty sure it means "is $var null".Also, what's the PHP reference?Thanks.

Link to comment
Share on other sites

!$var will evaluate to true if $var has a false value. The ! operator means "not", so you can read "!$var" as "not var". e.g.:

$var = false;if (!$var){  echo 'this will print';}if ($var){  echo 'this will not print';}

Other than the boolean value "false", this lists other values that are also considered to be false:http://www.php.net/manual/en/language.types.boolean.phpA value of null is one of the values that will evaluate to false.

Link to comment
Share on other sites

So, "(!$name)" is a way of testing whether someone failed to enter their name on a form ( a null name will return a false). Correct? Thanks.

Link to comment
Share on other sites

So, "(!$name)" is a way of testing whether someone failed to enter their name on a form ( a null name will return a false). Correct? Thanks.
You'll get a warning if you try something like this:$name = $_POST['name']if (!$name) . . .and the 'name' element was left blank. If blank, the browser will not send it as part of the post data, so that $_POST['name'] doesn't actually exist. The first statement throws the warning.There are two alternatives. Both are okay, but the test is a little different:if (isset($_POST['name'])) returns true if and only if a name element was included as part of the post data.if (!empty($_POST['name'])) returns true if a name element was included AND has a value attached. Edited by Deirdre's Dad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...