
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between 'isset()' and '!empty()' in PHP?
Isset function
ISSET checks the variable to see if it has been set. In other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a "", 0, "0", or FALSE are set, and therefore are TRUE for ISSET.
Example
<?php $val = '0'; if( isset($val)) { print_r(" $val is set with isset function <br>"); } $my_array = array(); echo isset($my_array['New_value']) ? 'array is set.' : 'array is not set.'; ?>
Output
This will produce the following output −
0 is set with isset function array is not set.
!empty function
EMPTY checks to see if a variable is empty. Empty is interpreted as: "" (an empty string), 0 (integer), 0.0 (float)`, "0" (string), NULL, FALSE, array() (an empty array), and "$var;" (a variable declared, but without a value in a class.
Example
<?php $temp_val = 0; if (empty($temp_val)) { echo $temp_val . ' is considered empty'; } echo "nn"; $new_val = 1; if (!empty($new_val)) { echo $new_val . ' is considered set'; } ?>
Output
This will produce the following output −
0 is considered empty 1 is considered set
- Related Questions & Answers
- What is difference between '.' , '?' and '*' in Python regular expression?
- what is the main difference between '=' and '==' operators in javascript?
- What is the difference between 'log' and 'symlog' in matplotlib?
- The difference between 'AND' and '&&' in MySQL?
- What is the difference between the 'COPY' and 'ADD' commands in a Dockerfile?
- Difference between 'include' and 'extend' in Ruby
- What is the difference between 'throw new Error' and 'throw someObject' in javascript?
- Write the main difference between '==' and '===' operators in javascript?
- Difference between 'struct' and 'typedef struct' in C++?
- Difference between 'struct' and 'typedef struct' in C++ program?
- What is the difference between 'except Exception as e' and 'except Exception, e' in Python?
- What is the relation between 'null' and '0' in JavaScript?
- What does the '@' prefix do in PHP?
- Finding the sum of two numbers without using '+', '-', '/', '*' in JavaScript
- Update 'a' record with 'b' and 'b' with 'a' in a MySQL column (swap) with only 'a' and 'b' values?
Advertisements