Re: [PHP] testing a variable
--- Adam Williams <[EMAIL PROTECTED]> wrote: > I need to test a variable to see if it contains a value or not, and if > not, do something. My php is a little rusty, so which would be better? This is a good page for understanding how things like isset(), is_null(), and empty() work: http://www.blueshoes.org/en/developer/php_cheat_sheet Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing a variable
Adam Williams said the following on 11/12/2003 11:37 AM>> Hello, I need to test a variable to see if it contains a value or not, and if not, do something. My php is a little rusty, so which would be better? if ( !$var ) { echo "do something";} or if ( !isset($var ) { echo "do something";} or are both of those wrong, and if so, how hsoudl I check if a variable is false, null, doesn't contain a value, etc... What I am doing is checking a field in an sql table, and if the field is null, empty, etc... then do something. so what is the best way to check the field if its null, empty, etc...? if (!isset($var) or empty($var) ) { echo "do something"; } HTH R'twick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing a variable
From: "Adam Williams" <[EMAIL PROTECTED]> > I need to test a variable to see if it contains a value or not, and if > not, do something. [snip] > if ( !isset($var ) > { echo "do something";} That's the correct way. > What I am doing is checking a field in an sql table, and if the field is > null, empty, etc... then do something. so what is the best way to check > the field if its null, empty, etc...? The variable might be set, yet empty, though. So you may want to add if(!isset($var) || empty($var)) { echo "do something"; } ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] testing a variable
[snip] if ( !isset($var ) { echo "do something";} [/snip] self answering questions, gotta' love 'em! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] testing a variable
Hello, I need to test a variable to see if it contains a value or not, and if not, do something. My php is a little rusty, so which would be better? if ( !$var ) { echo "do something";} or if ( !isset($var ) { echo "do something";} or are both of those wrong, and if so, how hsoudl I check if a variable is false, null, doesn't contain a value, etc... What I am doing is checking a field in an sql table, and if the field is null, empty, etc... then do something. so what is the best way to check the field if its null, empty, etc...? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php