oop - search php object for empty value -
looking best way accomplish below. want return true if empty in user object, don't care 1 empty. think i've done before searching empty values in array can't think of best way objects.
i know can loop thru object , break once find empty value in object, checking first see if there 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 $u): if( isset ($user->value) ): // or should isset? return true; break; endif; endforeach; return true; }
$user = new stdclass(); $user->firstname = 'mark'; $user->lastname = 'baker'; $user->sanity = null; function is_it_empty($user) { foreach($user $property) { if (empty($property)) { return true; } } return false; } var_dump(is_it_empty($user));
Comments
Post a Comment