Skip to content
- Tutorials
- Python Tutorial
- Taking Input in Python
- Python Operators
- Python Data Types
- Python Loops and Control Flow
- Python Functions
- Python OOPS Concept
- Python Data Structures
- Python Exception Handling
- Python File Handling
- Python Exercises
- Java
- Java Programming Language
- Java Collections
- Java 8 Tutorial
- Java Programs
- Java Interview Questions
- Java Exercises
- Java Quiz
- Java Projects
- Advance Java
- Programming Languages
- System Design
- Interview Corner
- Computer Science Subjects
- DevOps
- Linux
- Software Testing
- Databases
- Android
- Excel
- Mathematics
- Commerce
- Aptitude
- Python Tutorial
- DSA
- Data Structures
- Algorithms
- Analysis of Algorithms
- Searching Algorithms
- Sorting Algorithms
- Greedy Algorithms
- Dynamic Programming
- Graph Algorithms
- Pattern Searching
- Recursion
- Backtracking
- Divide and Conquer
- Mathematical Algorithms
- Geometric Algorithms
- Bitwise Algorithms
- Randomized Algorithms
- Branch and Bound
- Algorithms Tutorial
- DSA Tutorial
- Practice
- All DSA Problems
- Problem of the Day
- Company Wise Coding Practice
- GfG SDE Sheet
- Practice Problems Difficulty Wise
- Language Wise Coding Practice
- Curated DSA Lists
- Competitive Programming
- Company Wise SDE Sheets
- DSA Cheat Sheets
- Top Interview Questions
- Puzzles
- Data Science
- Web Tech
- Courses
-
- Difference between isset() and empty() Functions
- Difference between die() and exit() functions in PHP
- Difference between isset() and array_key_exists() Function in PHP
- Difference between “!==” and “==!” in PHP
- Why to check both isset() and !empty() function in PHP ?
- What is the Difference Between unset and null in PHP ?
- D3.js | d3.set.empty() Function
- What is the difference between var_dump() and print_r() in PHP ?
- Difference Between Void and Non Void Methods in Java
- Difference between Set.clear() and Set.delete() Methods in JavaScript
- Explain the differences between empty() remove() and detach() methods in jQuery
- Difference Between WHERE FIND_IN_SET(…)>0 and WHERE FIND_IN_SET(…) in SQL
- Difference between NULL pointer, Null character ('\0') and '0' in C with Examples
- D3.js selection.empty() Function
- D3.js | d3.map.empty() Function
- list empty() function in C++ STL
- Deque::empty() and deque::size() in C++ STL
- bitset all() function in C++ STL
- multiset empty() function in C++ STL
- list::empty() and list::size() in C++ STL
Last Updated : 23 Sep, 2021
Improve
Improve
Like Article
Like
Save
Report
The empty() function is an inbuilt function in PHP that is used to check whether a variable is empty or not.
These values are considered to be empty values:
- “” ( an empty string)
- 0 ( 0 as an integer)
- 0.0 ( 0 as a float)
- “0” ( 0 as a string)
- NULL
- FALSE
- array() (an empty array)
Example: Below example illustrate the empty() function in PHP.
PHP
<?php
// PHP code to demonstrate the working
// of empty() function
See AlsoW3Schools.comHow to Check If an Array Is Empty in PHPWhen to Use NULL and When to Use Empty String$var1
= 0;
$var2
= 0.0;
$var3
=
"0"
;
$var4
= NULL;
$var5
= false;
$var6
=
array
();
$var7
=
""
;
// For value 0 as integer
empty
(
$var1
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
// For value 0.0 as float
empty
(
$var2
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
// For value 0 as string
empty
(
$var3
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
// For value Null
empty
(
$var4
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
// For value false
empty
(
$var5
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
// For array
empty
(
$var6
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
// For empty string
empty
(
$var7
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
// For not declare $var8
empty
(
$var8
) ? print_r(
"True\n"
) : print_r(
"False\n"
);
?>
Output
TrueTrueTrueTrueTrueTrueTrueTrue
isset() Function: The isset() function is an inbuilt function in PHP that is used to determine if the variable is declared and its value is not equal to NULL.
Parameters: This function accepts one or more parameters as mentioned above and described below.
- $var: It contains the variable which needs to check.
- $…: It contains the list of other variables.
Return Value: It returns TRUE if var exists and its value is not equal to NULL and FALSE otherwise.
Example 2: Below examples illustrate the isset() function in PHP:
PHP
<?php
$str
=
"GeeksforGeeks"
;
// Check value of variable is set or not
if
(isset(
$str
)) {
echo
"Value of variable is set"
;
}
else
{
echo
"Value of variable is not set"
;
}
$arr
=
array
();
// Check value of variable is set or not
if
( !isset(
$arr
[0]) ) {
echo
"\nArray is Empty"
;
}
else
{
echo
"\nArray is not empty"
;
}
?>
Output
Value of variable is setArray is Empty
PHP program using both isset() and empty() functions:
PHP
<?php
// PHP function to demonstrate
// isset() and !empty() function
// initialize a variable
$num
=
'0'
;
// Check isset() function
if
( isset (
$num
) ) {
print_r(
$num
.
" is set with isset function"
);
}
// Display new line
echo
"\n"
;
// Initialize a variable
$num
= 1;
// Check the !empty() function
if
( !
empty
(
$num
) ) {
print_r(
$num
.
" is set with !empty function"
);
}
?>
Output:
0 is set with isset function1 is set with !empty function
Difference between isset() and empty() function:
isset() Function
empty() Function
The isset() function is an inbuilt function in PHP that is used to determine if the variable is declared and its value is not equal to NULL. The empty() function is an inbuilt function in PHP that is used to check whether a variable is empty or not. The isset() function will generate a warning or e-notice when the variable does not exists. The empty() function will not generate any warning or e-notice when the variable does not exists.
Improve
Please Login to comment...
Similar Reads
Why to check both isset() and !empty() function in PHP ?
isset() Function The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases. Syntax: bool isset( $var, mixed ) Parameters: This function a
3 min read
Difference between isset() and array_key_exists() Function in PHP
isset() function The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases. Syntax: bool isset( $var, mixed ) Parameters: This function a
2 min read
PHP | isset() Function
The isset() function is an inbuilt function in PHP which is used to determine if the variable is declared and its value is not equal to NULL. Syntax: bool isset( mixed $var [, mixed $... ] ) Parameters: This function accept one or more parameter as mentioned above and described below: $var: It contains the variable which need to check. $...: It con
2 min read
PHP | IntlCalendar isSet() Function
The IntlCalendar::isSet() function is an inbuilt function in PHP which is used to check whether a given field is set or not. This function is opposite to IntlCalendar::clear() function. Syntax: Object oriented style bool IntlCalendar::isSet( int $field ) Procedural style bool intlcal_is_set( IntlCalendar $cal, int $field ) Parameters: This function
1 min read
Node.js util.types.isSet() Method
The util.types.isSet() method of the util module is primarily designed to support the needs of Node.js own Internal APIs. It is used to check whether the passed instance in the method is a built-in Set instance or not. Syntax: util.types.isSet( value ) Parameters: This method accepts a single parameter value that holds any value i.e instance of any
2 min read
Underscore.js _.isSet() Function
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isSet() function is used to check whether the given object is javascript set or not. When linking the underscore.js CDN The "_" is attached to the browser as global variable. Syntax: _.isSet(object); Parameters: object: It is any JavaS
2 min read
Lodash _.isSet() Method
Lodash _.isSet() method is used to find whether the given value is classified as a Set object or not. It returns True if the given value is a set. Otherwise, it returns false. Syntax:_.isSet(value)Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter holds the value to check.Return Value: T
2 min read
Difference between Regular functions and Arrow functions
This article discusses the major differences between regular functions and arrow functions. Arrow functions - a new feature introduced in ES6 - enable writing concise functions in JavaScript. While both regular and arrow functions work in a similar manner, there are certain interesting differences between them, as discussed below. Syntax: Regular f
2 min read
Difference Between deque::assign and deque::empty in C++
Deque or Double-ended queues are sequence containers with the feature of expansion and contraction on both ends. They are similar to vectors, but are more efficient in the case of insertion and deletion of elements at the end, and also the beginning. Unlike vectors, contiguous storage allocation may not be guaranteed. Here we will see the differenc
2 min read
What are User-defined Functions and Built-in Functions in PHP?
In PHP, User-defined functions are created by programmers to meet specific requirements, while PHP built-in functions are provided by PHP to perform common tasks without the need for manual implementation. Both types of functions play crucial roles in PHP development, offering flexibility, modularity, and efficiency in coding. Table of Content User
2 min read
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, check: true }), success:function(result) { jQuery.ajax({ url: writeApiUrl + 'suggestions/auth/' + `${post_id}/`, type: "GET", dataType: 'json', xhrFields: { withCredentials: true }, success: function (result) { $('.spinner-loading-overlay:eq(0)').remove(); var commentArray = result; if(commentArray === null || commentArray.length === 0) { // when no reason is availaible then user will redirected directly make the improvment. // call to api create-improvement-post $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); return; } var improvement_reason_html = ""; for(var comment of commentArray) { // loop creating improvement reason list markup var comment_id = comment['id']; var comment_text = comment['suggestion']; improvement_reason_html += `
${comment_text}
`; } $('.improvement-reasons_wrapper').html(improvement_reason_html); $('.improvement-bottom-btn').html("Create Improvement"); $('.improve-modal--improvement').hide(); $('.improvement-reason-modal').show(); }, error: function(e){ $('.spinner-loading-overlay:eq(0)').remove(); // stop loader when ajax failed; }, }); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ $('.improvement-reason-modal').hide(); } $('.improve-modal--improvement').show(); }); jQuery('.suggest-bottom-btn').on('click', function(){ var suggest_val = $.trim($("#suggestion-section-textarea").val()); var error_msg = false; if(suggest_val != ""){ if(suggest_val.length <= 2000){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify({ "gfg_post_id" : `${post_id}`, "suggestion" : `
${suggest_val}
` }), success:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-section-textarea').val(""); jQuery('.suggest-bottom-btn').html("Sent "); setTimeout(() => { jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); }, 1000); }, error:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('#suggestion-modal-alert').html("Character limit exceeded."); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } } else{ jQuery('#suggestion-modal-alert').html("Enter valid input."); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('#suggestion-section-textarea').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } }) $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.improvement-reason-modal').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); });