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
Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AJAX pass along a variable 3 46
How do I correctly structure this?   PHP / PDO / CSV download 1 20
if (is_singular not working 5 18
PHP 5.6 and 7.x 4 23
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

861 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