Check for Empty String, $_POST, $_GET function

183 views
Skip to first unread message

roja...@gmail.com

unread,
Dec 27, 2007, 4:04:51 PM12/27/07
to Connecticut PHP Developers Group - CPDG
This function will allow you to check if a value is empty or NULL.,
very useful on forms.

---------------------------------------------------------------------------------------------------------------------------


function checkEmpty($variable){
if($variable == NULL || $variable == ''){
$isempty = true;
} else {
$isempty = false;
//End if
}


-------------------------------------------------------------------------------------------------------------------------

Will

unread,
Dec 27, 2007, 9:49:58 PM12/27/07
to Connecticut PHP Developers Group - CPDG
You forgot a return statement. Add <code>return $isempty;</code> after
you close the else block.

Because this function simply returns the value of a conditional test,
its possible to write this function with only one line in the function
body:
<pre>function checkEmpty($variable) {
return ($variable == NULL || $variable == '')
}</pre>

roja...@gmail.com

unread,
Dec 27, 2007, 10:24:58 PM12/27/07
to Connecticut PHP Developers Group - CPDG
Updated Code:

function checkEmpty($variable){
if($variable == NULL || $variable == ''){
$isempty = true;
} else {

$isempty = false;
//End if

}

return($isempty);
}

------------/// That Should do it ///------
Thanks will for pointing it out.
Reply all
Reply to author
Forward
0 new messages