Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP variables to be empty string or NULL in making a determination.
<?php
// bad example
$v = '0';
if ( empty($v) ) {
echo '$v is blank.';
}
// good example
$v = '0';
if ( strlen($v)==0 ) {
echo '$v is blank.';
}
// or use is_blank function
function is_blank($str) {
return strlen($v)===0;
}
if ( is_blank($v) ) {
echo '$v is blank.'
}
// It is safer to write PHP code that you can type Even with awareness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment