niche Posted October 26, 2009 Share Posted October 26, 2009 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 More sharing options...
justsomeguy Posted October 26, 2009 Share Posted October 26, 2009 !$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 More sharing options...
niche Posted October 26, 2009 Author Share Posted October 26, 2009 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 More sharing options...
jeffman Posted October 26, 2009 Share Posted October 26, 2009 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 26, 2009 Share Posted October 26, 2009 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?The expression !$name will evaluate to true if $name evaluates to false. Nothing more, nothing less. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.