Re: Determine whether $_GET has a value
| From: | Brent Baisley | Date: | Thu, 24 Jun 2004 14:51:16 +0000 |
| Subject: | Re: Determine whether $_GET has a value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188960@lists.php.net to get a copy of this message | ||
This is a thorny topic for some people to grasp. The way I finally figured it out is that there are three answers to a yes and no question: yes, no and no answer. Or, to put it in boolean terms 1,0,NULL. It's that third option in a two option multiple choice question that throws things.
What you may be looking for is the triple equals for comparison, which works by "typing" the value. For example:
$testVar = NULL;
$testVar == ''; is true
$testVar === ''; is false
$testVar = 0;
$testVar == '0'; is true
$testVar === '0'; is false
$testVar == NULL; is true
$testVar === NULL; is false
Hope that helps a little.
On Jun 23, 2004, at 11:13 PM, Terence wrote:
Hi, Say you have a querystring - index.php?myname=joe To determine whether myname has a value I have come to the following conclusions / shortcomings when using one of the following: ISSET = as long as the variable myname exists it's set, but there's no guarantee of a value !EMPTY = if your name = 0 (zero) then it's considered empty, for all else it seems to work STRLEN = I have found this to be the only sure way to know. Is there any other way, or should we always use a combination of ISSET and STRLEN? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577