Looking for best way to accomplish below. I want to return TRUE if ANYTHING is empty in my user object, I don't care which one is empty. I think I've done this before with searching for empty values in an array but can't think of the best way to do this with objects.
I know I can loop thru the object and break once I find an empty value in the object, but checking first to see if there is a better way of doing this, thanks!
function is_it_empty($user)
{
$is_it_empty = FALSE;
if( isset($user->first_name) )
$is_it_empty = TRUE;
if( isset($user->last_name) )
$is_it_empty = TRUE;
return $is_it_empty;
}
also:
function name($user)
{
foreach($user as $u):
if( isset ($user->value) ): // or should it be isset?
return true;
break;
endif;
endforeach;
return true;
}
empty()checks if a variable "does not exist or if its value equals FALSE".empty($var)is equivalent to!isset($var) || $var == false. An array with zero elements is "empty" by this definition, and so is a string with zero characters, and the integer zero.