Skip to main content

What is empty() in PHP?

Junior PHP
Quick Answer empty() returns true if a variable is: not set, null, false, 0, 0.0, "0", "" (empty string), or [] (empty array). Different from isset() - empty also catches zero and empty strings. Use empty() when you want to check if a value is meaningless/absent. Caution: empty(0) is true, so use carefully with numeric values. isset($var) && $var !== "" is more explicit.

Answer

empty() checks if a variable contains an empty or falsy value (0, "", null, false).
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice