isset() function in PHP

By: Emiley J. Emailed: 1648 times Printed: 2123 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

isset() determines whether a certain variable has already been declared by PHP. It returns a boolean value true if the variable has already been set, and false otherwise, or if the variable is set to the value NULL.

Consider the following script:

if (isset($first_name)) {

print '$first_name is set';

}

This code snippet checks whether the variable $first_name is defined. If $first_name is defined, isset() returns true , which will display ' $first_name is set. ' If it isn’t, no output is generated.

isset() can also be used on array elements and object properties. Here are examples for the relevant syntax, which you can refer to later:.

Checking an array element:

if (isset($arr["offset"])) {

...

}

Checking an object property:

if (isset($obj->property)) {

...

}

Note that in both examples, we didn’t check if $arr or $obj are set (before we checked the offset or property, respectively). The isset() construct returns false automatically if they are not set.

isset() is the only one of the three language constructs that accepts an arbitrary amount of parameters. Its accurate prototype is as follows:

isset($var1, $var2, $var3, ...);

It only returns true if all the variables have been defined; otherwise, it returns false. This is useful when you want to check if the required input variables for your script have really been sent by the client, saving you a series of single isset() checks.


PHP Home | All PHP Tutorials | Latest PHP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(17)


1. View Comment

Simple and straightforward. Thats what I like about this site.

View Tutorial          By: Barand at 2009-03-21 11:03:47
2. View Comment

Thanks, how about using isset() function on page/UR? e.g. if(isset($page)) {} ??? What is it for?

View Tutorial          By: Paolo at 2009-06-01 07:29:10
3. View Comment

Fine,you r very straightforward I like that
Thanks


View Tutorial          By: Shaiju at 2010-02-21 10:15:00
4. View Comment

i can understand easily what is isset but i am not clear in array example (second one) partially understood
its very easy because of lack of english knowledge i can' t usnderstand


View Tutorial          By: sebestiraj at 2010-04-09 00:09:36
5. View Comment

thanks i learnt how to use isset in php

View Tutorial          By: free web directory at 2010-09-15 19:42:28
6. View Comment

now I know what isset is for, thank you very much

View Tutorial          By: Anonymous at 2010-12-23 20:43:29
7. View Comment

I can't get it untill now. I need further explainations about it.

View Tutorial          By: johnlie at 2011-01-19 20:31:09
8. View Comment

please give example code with defined variable.

View Tutorial          By: shajjad at 2011-02-13 20:56:09
9. View Comment

what about (!isset)?? the isset with "!" ?? what that mean?? i'm still confused about that.
thanks


View Tutorial          By: bali web design at 2011-04-21 12:51:38
10. View Comment

but need in the case of radio buttons

View Tutorial          By: vishnu at 2011-07-21 11:39:26
11. View Comment

dat is wat i want to jegay with you ,......dats kool ,

View Tutorial          By: dorji wangmo at 2011-12-27 05:38:35
12. View Comment

Thanks..
Short & Sweet Description.

This is very helpful to upcoming webmasters..


View Tutorial          By: Prashaad at 2012-02-23 17:37:14
13. View Comment

my question is the same of sajjad.what about (!isset)?? the isset with "!" ?? what that mean?? i'm still confused about that.
thanks


View Tutorial          By: hossain at 2012-04-26 04:28:56
14. View Comment

The !isset() is basically checking if the string is NOT true.
Take the first example:
if (isset($first_name)) {

print '$first_name is set';

}
This checks if the var $first_name has been declared. In plain English, if user hasn't filled out the form "First Name" yet then it will return false when he submit it.
Now:
if (!isset($first_name)) {

//So the $first_name is not set obviously, not you want to notify the user that he must
//have it filled

print 'Please fill out your First Name';

}
For this one you are checking if the $first_name has NOT been declared. The "!" means "NOT", this is listed in the operators http://www.w3schools.com/php/php_operators.asp
There are two or more ways to do this and it depends on what your are tying to achieve.
I am not a "PRO" at php just yet since I just stated but you'll know this but reading the link I gave.Also please if I said something wrong please correct me. ^_^


View Tutorial          By: Bijan at 2012-09-21 20:49:41
15. View Comment

I lik the description.

View Tutorial          By: Praveen saini at 2012-11-05 10:13:41
16. View Comment

if(isset($_POST["check1"]=="1"))
{
$check1 = $_POST["check1"];
echo "check1 is checked\n";
}

This shows me an error in first line...
i am not sure about the syntax...
plz help whether it is proper or not...


View Tutorial          By: krunal at 2012-11-22 10:30:19
17. View Comment

how to use isset keyword with multidimensional array

View Tutorial          By: mehul at 2015-01-19 23:47:02

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Emiley J.
Error generating R.java from manifest
ERROR 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client
IIS and Tomcat - how to configure to work together
PHP Warning: Unknown(): Unable to load dynamic library '/usr/local/php4/lib/php/extensions/no-debug ......
Adding your own Application icon for your J2ME application (jar file)
Creating Menus in Code using VB.net
Traversing all files in a directory using Ruby
Using Proxy to connect to URLs in Ruby
POST a form in Ruby
Reading URL content using Ruby (HTTP)
dRuby client/server mode sample program
Benchmark module in Ruby
encoding and decoding in Ruby using Base64 Module
Module Abbrev in Ruby
Standard Library Packages in Ruby

More Tutorials in PHP
PHP code to import from CSV file to MySQL
PHP code to write to a CSV file from MySQL query
PHP code to write to a CSV file for Microsoft Applications
Convert XML to CSV in PHP
Password must include both numeric and alphabetic characters - Magento
PHP file upload (Large Files)
PHP file upload prompts authentication for anonymous users
PHP file upload with IIS on windows XP/2000 etc
Error: Length parameter must be greater than 0
Multiple File Upload in PHP using IFRAME
Resume or Pause File Uploads in PHP
Exception in module wampmanager.exe at 000F15A0 in Windows 8
Handling file locks in PHP
HTML table output using Nested for loops in PHP
Count occurrences of a character in a String in PHP

More Latest News
Most Viewed Articles (in PHP )
Exception in module wampmanager.exe at 000F15A0 in Windows 8
isset() function in PHP
Handling BLOB in PHP and MySQL
Reading Cookie Values in PHP
Parent: child process exited with status 3221225477 -- Restarting
Cannot load /usr/local/apache/libexec/libphp4.so into server: ld.so.1:......
Get the next working day in PHP
Return multiple values from a function in PHP
History and origin of PHP
.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
superglobals in PHP
Reading contents of a File into a String in PHP
Reading word by word from a file in PHP
XMLRPC for PHP - A simple client and server program
Where does the PHP run?
Most Emailed Articles (in PHP)
PHP code to write to a CSV file for Microsoft Applications
PHP code to write to a CSV file from MySQL query
PHP code to import from CSV file to MySQL
Convert XML to CSV in PHP
Using PEAR::Crypt_HMAC in PHP
Password must include both numeric and alphabetic characters - Magento
GDBM, NDBM, DB2, DB3, DBM, and CDB Databases in PHP
Resume or Pause File Uploads in PHP
Comparison operators in PHP
Extract files from a .zip file using PHP
Appending One Array to Another in PHP
Exception in module wampmanager.exe at 000F15A0 in Windows 8
isset() function in PHP
do...while Loops in PHP
Counting Lines, Paragraphs, or Records in a File using pc_split_paragraphs() in PHP