validation - check for empty value in php -
i checking value see if empty using empty()
function in php. validates following empty:
"" (an empty string) 0 (0 integer) 0.0 (0 float) "0" (0 string) null false array() (an empty array) $var; (a variable declared, without value)
the value passing can string, array or number. if string has space (" "
) not considered empty. easiest way check condition without creating own function? cannot empty(trim($value))
since $value
can array
.
edit: not trying ask how check if string empty. know that. asking if there way can pass array, number or string empty() , return correct validation if string passed has empty spaces in them.
the best way create own function, if have reason not can use this:
$original_string_or_array = array(); // variable want check $trimed_string_or_array = is_array($original_string_or_array) ? $original_string_or_array : trim($original_string_or_array); if(empty($trimed_string_or_array)) { echo 'the variable empty'; } else { echo 'the variable not empty'; }
Comments
Post a Comment