Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
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…

914 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

19 Experts available now in Live!

Get 1:1 Help Now