Solved

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

Posted on 2004-08-11
4
239 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

11 Experts available now in Live!

Get 1:1 Help Now