PHP empty() method is used to check the variable has value or not. It gives output in a boolean value. if the variable empty then the output will be true or 1 and if the variable is not empty then the output will be false or 0.
Syntax:- to check the variable is empty
<?php
empty($variable_name)
?>
Example:- Suppose, You have employee_name variable which has empty value and now you want to check employee_name variable is empty or not.
<?php
$employee_name="";
if(empty($employee_name))
{
echo 'employee is empty';
}
?>
Output:- employee is empty
Php empty() method – Interview Questions
Q 1: What is empty() in PHP?
Ans: It checks whether a variable is empty.
Q 2: What values are considered empty?
Ans: "", 0, NULL, false, and empty arrays.
Q 3: What does empty() return?
Ans: true or false.
Q 4: Does empty() generate warnings?
Ans: No.
Q 5: Difference between isset() and empty()?
Ans: isset() checks existence; empty() checks value.
Php empty() method – Objective Questions (MCQs)
Q1. empty() checks whether a variable is ______.
Q2. empty() returns ______.
Q3. Which of the following is considered empty?
Q4. empty() is faster than ______.
Q5. Can empty() be used on undeclared variables?