Solved

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

Posted on 2004-08-11
4
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
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.

696 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