[PHP] test variable value?
Hello What is the best way to determine if a variable has no value? if ($var= '') or if ($var= 'null') Can 'null' be used here? Thanks -Willa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] test variable value?
Hello What is the best way to determine if a variable has no value? if ($var== '') or if ($var== 'null') Can 'null' be used here? Thanks -Willa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
William Stokes wrote: Hello What is the best way to determine if a variable has no value? if ($var== '') or if ($var== 'null') Can 'null' be used here? yeah buts its a string which doesn't do what you want. if (empty($var)) { echo 'yes'; } or: if (is_null($var)) { echo 'yes'; } Thanks -Willa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
William Stokes wrote: Hello What is the best way to determine if a variable has no value? if ($var== '') or if ($var== 'null') Can 'null' be used here? Depends what you mean by no value. I suggest you read http://php.net/is_null, http://php.net/empty and http://php.net/isset. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
How about... if (!$x){ echo x is empty; } Regards, Rodolfo Andradee - Original Message - From: Stut To: William Stokes Cc: php-general@lists.php.net Sent: Wednesday, January 11, 2006 8:08 AM Subject: Re: [PHP] test variable value? William Stokes wrote: Hello What is the best way to determine if a variable has no value? if ($var== '') or if ($var== 'null') Can 'null' be used here? Depends what you mean by no value. I suggest you read http://php.net/is_null, http://php.net/empty and http://php.net/isset. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
Rodolfo Andrade wrote: How about... if (!$x){ echo x is empty; } Because $x could be an empty string, 0, false, null or undefined. If that's what you need to check for then knock yourself out. -Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
I do use if(!$var) for simple application. Only _IF_ I need to know if the $var is defined but empty or so I would use especific functions. - Original Message - From: Stut To: Rodolfo Andrade Cc: William Stokes ; php-general@lists.php.net Sent: Wednesday, January 11, 2006 11:49 AM Subject: Re: [PHP] test variable value? Rodolfo Andrade wrote: How about... if (!$x){ echo x is empty; } Because $x could be an empty string, 0, false, null or undefined. If that's what you need to check for then knock yourself out. -Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
remember though that if(!$x) { echo 'nothing here'; } will also output 'nothing here' when provided with the string '0'! - tul Rodolfo Andrade wrote: I do use if(!$var) for simple application. Only _IF_ I need to know if the $var is defined but empty or so I would use especific functions. - Original Message - From: Stut To: Rodolfo Andrade Cc: William Stokes ; php-general@lists.php.net Sent: Wednesday, January 11, 2006 11:49 AM Subject: Re: [PHP] test variable value? Rodolfo Andrade wrote: How about... if (!$x){ echo x is empty; } Because $x could be an empty string, 0, false, null or undefined. If that's what you need to check for then knock yourself out. -Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
Gerry Danen wrote: On 1/11/06, M. Sokolewicz [EMAIL PROTECTED] wrote: remember though that if(!$x) { echo 'nothing here'; } will also output 'nothing here' when provided with the string '0'! That's because (!$x) means ($x == false) and '0' is false... Gerry I know that, and you know that, as do others who have encountered problems with this before; just wanted to make a small warning so the OP wouldn't get hit by this - tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] test variable value?
On 1/11/06, M. Sokolewicz [EMAIL PROTECTED] wrote: remember though that if(!$x) { echo 'nothing here'; } will also output 'nothing here' when provided with the string '0'! That's because (!$x) means ($x == false) and '0' is false... Gerry