

How to check whether a variable is empty in PHP
source link: https://www.laravelcode.com/post/how-to-check-whether-a-variable-is-empty-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to check whether a variable is empty in PHP
Use the PHP empty()
function
You can use the PHP empty()
function to find out whether a variable is empty or not. A variable is considered empty if it does not exist or if its value equals FALSE
.
Let's try out the following example to understand how this function basically works:
<?php
$var1 = '';
$var2 = 0;
$var3 = NULL;
$var4 = FALSE;
$var5 = array();
// Testing the variables
if(empty($var1)){
echo 'This line is printed, because the $var1 is empty.';
}
echo "<br>";
if(empty($var2)){
echo 'This line is printed, because the $var2 is empty.';
}
echo "<br>";
if(empty($var3)){
echo 'This line is printed, because the $var3 is empty.';
}
echo "<br>";
if(empty($var4)){
echo 'This line is printed, because the $var4 is empty.';
}
echo "<br>";
if(empty($var5)){
echo 'This line is printed, because the $var5 is empty.';
}
?>
i hope you like this small article.

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
-
6
How to Check if an Object is Empty in JavaScript In this quick article, I’ll show you how you can check if an object is empty in JavaScript. In your day-to-day JavaScript development, might nee...
-
8
If the variable is empty then no clause where [Multiple] advertisements This question is similar to this one The only difference is I h...
-
9
Check the entry is not empty on sending click after that show another div advertisements I am new to jquery, I have sign up form with 4 input...
-
9
While working with arrays in javascript, often there is a requirement to check if an array is empty or not. This article will describe how to check if an array is empty or exists in javascript. Table of Contents:-...
-
6
How to Check if StringBuilder Is Empty Posted by Code Maze | Updated Date Dec 15, 2021 |
-
5
Javascript: Check If an Object Empty While working in javascript, we often encounter a requirement to determine if the object is empty. This check is required at times before operating on the properties or met...
-
7
How to check whether a variable is null in PHP 1483 views 2 years ago PHP Use the PHP is_null() f...
-
4
How to check whether a number is Fibonacci or not in PHP? Member by
-
13
How to check whether a variable is set or not in PHP 1600 views 2 years ago PHP Use the PHP isset()
-
7
This tutorial will discuss about unique ways to check if an array is empty or not in php. Table Of Contents Method 1: Using empty() function The empty() function in PHP ac...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK