isset() function in PHP

By: Emiley J. Viewed: 153567 times    

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.

Most Viewed Articles (in PHP )

Latest Articles (in PHP)

Comment on this tutorial

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. Simple and straightforward. Thats what I like abou
View Tutorial          By: Barand at 2009-03-21 11:03:47

2. Thanks, how about using isset() function on page/U
View Tutorial          By: Paolo at 2009-06-01 07:29:10

3. Fine,you r very straightforward I like that

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

4. i can understand easily what is isset but i am not
View Tutorial          By: sebestiraj at 2010-04-09 00:09:36

5. ds
View Tutorial          By: sdsd at 2010-08-31 04:05:46

6. thanks i learnt how to use isset in php
View Tutorial          By: free web directory at 2010-09-15 19:42:28

7. now I know what isset is for, thank you very much
View Tutorial          By: Anonymous at 2010-12-23 20:43:29

8. I can't get it untill now. I need further explaina
View Tutorial          By: johnlie at 2011-01-19 20:31:09

9. please give example code with defined variable.
View Tutorial          By: shajjad at 2011-02-13 20:56:09

10. what about (!isset)?? the isset with "!"
View Tutorial          By: bali web design at 2011-04-21 12:50:36

11. what about (!isset)?? the isset with "!"
View Tutorial          By: bali web design at 2011-04-21 12:51:38

12. but need in the case of radio buttons
View Tutorial          By: vishnu at 2011-07-21 11:39:26

13. this is very powerful document of isset method. th
View Tutorial          By: mehul patel at 2011-08-29 12:16:48

14. Hello ,
I have a problem in understanding c

View Tutorial          By: dimitra at 2011-10-05 16:24:11

15. It is so simple i like it,thnx...
View Tutorial          By: Shahid Hussain at 2011-12-14 12:37:46

16. dat is wat i want to jegay with you ,......dats ko
View Tutorial          By: dorji wangmo at 2011-12-27 05:38:35

17. so but I cannot use isset($var) instead of $var!=&
View Tutorial          By: Dan at 2012-01-12 19:23:09

18. this is very helpful...
View Tutorial          By: arrian at 2012-02-08 03:08:53

19. Thanks..
Short & Sweet Description.

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

20. Thanks ! very information full site
View Tutorial          By: Kedar at 2012-04-22 08:53:17

21. my question is the same of sajjad.what about (!iss
View Tutorial          By: hossain at 2012-04-26 04:28:56

22. The !isset() is basically checking if the string i
View Tutorial          By: Bijan at 2012-09-21 20:49:41

23. I lik the description.
View Tutorial          By: Praveen saini at 2012-11-05 10:13:41

24. if(isset($_POST["check1"]=="1"
View Tutorial          By: krunal at 2012-11-22 10:30:19

25. Stuypluz.com provides simple and easy way to learn
View Tutorial          By: Logeswari at 2013-04-09 05:55:25

26. Stuypluz.com provides simple and easy way to learn
View Tutorial          By: Logeswari at 2013-04-30 10:46:54

27. how to use isset keyword with multidimensional arr
View Tutorial          By: mehul at 2015-01-19 23:46:41

28. how to use isset keyword with multidimensional arr
View Tutorial          By: mehul at 2015-01-19 23:47:02

29. Guestchoob
View Tutorial          By: Guestchoob at 2017-03-02 05:59:38

30. KostyaExhat
View Tutorial          By: KostyaExhat at 2017-06-16 09:47:59