Solved

Explain how to use  (isset) and   (!) and a example

Posted on 2004-08-11
4
245 Views
Last Modified: 2013-12-12
I want a real good explantion of isset and ! can anyone give a written explantion on them and when and how to use them and a small commented example.
0
Comment
Question by:smphil
  • 4
4 Comments
 
LVL 9

Accepted Solution

by:
stefanaichholzer earned 500 total points
ID: 11777645
smphil,

Take a look at this:

isset
(PHP 3, PHP 4, PHP 5 )

isset -- Determine whether a variable is set
Description
bool isset ( mixed var [, mixed var [, ...]])


Returns TRUE if var exists; FALSE otherwise.

If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.

Warning: isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.



<?php

$var = '';

// This will evaluate to TRUE so the text will be printed.
if (isset($var)) {
   echo "This var is set set so I will print.";
}

// In the next examples we'll use var_dump to output
// the return value of isset().

$a = "test";
$b = "anothertest";

var_dump(isset($a));      // TRUE
var_dump(isset($a, $b)); // TRUE

unset ($a);

var_dump(isset($a));    // FALSE
var_dump(isset($a, $b)); // FALSE

$foo = NULL;
var_dump(isset($foo));  // FALSE

?>  



This also work for elements in arrays:


<?php

$a = array ('test' => 1, 'hello' => NULL);

var_dump(isset($a['test']));            // TRUE
var_dump(isset($a['foo']));            // FALSE
var_dump(isset($a['hello']));          // FALSE

// The key 'hello' equals NULL so is considered unset
// If you want to check for NULL key values then try:
var_dump(array_key_exists('hello', $a)); // TRUE

?>  

Note: Because this is a language construct and not a function, it cannot be called using variable functions

Hope that works for you...

;)

0
 
LVL 9

Expert Comment

by:stefanaichholzer
ID: 11777670
For more info you may wanna check out the PHP Manual at www.php.net

;)
0
 
LVL 9

Expert Comment

by:stefanaichholzer
ID: 11777688
! is just the negation of something you could get as a boolean result, for example isset() return a boolean type, if you use !isset() you are just asking for the false option of that boolean variable...

;)
0
 
LVL 9

Expert Comment

by:stefanaichholzer
ID: 11777696
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now