Hi, What is the best way to write an if statement to check whether a variable is empty? The variable in question is a field of a table retrieved from a database. Any ideas?
theres a better way, php has a built in function for doing this If (empty($some_var)){ //code here will execute if $some_var is empty } PHP: if you wanted to see if it wasn’t empty (i.e. it has a value) then do If (!empty($some_var)){ //code here will execute if $some_var has something in it } PHP: mor einfo here: http://uk3.php.net/manual/en/function.empty.php
It depends on what you mean with "empty", but this might be what you want: http://www.php.net/manual/en/function.empty.php
Basically I know certain values in the database are set to NULL. How would I check if a variable was not NULL? Is this the same as empty?
null is NOT the same as empty. you would use the inbuilt php function is_null, so in your case you would use: if (!is_null($var)){ //code here will execute if $var is NOT null } http://uk3.php.net/manual/en/function.is-null.php