[link]http://php.net/manual/en/function.isset.php[/link]

Clearly states that "isset — Determine if a variable is set and is not NULL"?

I have been trying to use isset() to check values for NULL and it still appears yet when I use != NULL then it works. I think the fine line is in various instances but if anyone can confirm my conclusions:
1. $variable = "" > value SET
2. $variable = "a" > value SET
3. no definition > value NOT SET
4. $variable = 0 > value NOT SET
5. $variable = NULL > value NOT SET

any other examples?
Inparticular the 1. and 4. should be noted as I thought 1. would be NOT SET and 4. should be SET but it seems they are not through testing. Anyone confirm these as they dont seem logical to me?

Thanks, Regards X

PS: If anyone has anything else to add go ahead.

I think what your looking for is the empty() function Below is an example.

<?php
$arr=array('','a',0,NULL);
echo '//empty<br>';
$i=1;
foreach ($arr AS $val) {
if (empty($val) {
echo $i.' passed<br>'; }
$i++;
}

echo '//isset<br>';
$i=1;
foreach ($arr AS $vals) {
if (isset($vals)) {
echo $i.' passed<br>'; }
$i++;
}

[link]http://php.net/manual/en/function.isset.php[/link]

Clearly states that "isset — Determine if a variable is set and is not NULL"?

I have been trying to use isset() to check values for NULL and it still appears yet when I use != NULL then it works. I think the fine line is in various instances but if anyone can confirm my conclusions:
1. $variable = "" > value SET
2. $variable = "a" > value SET
3. no definition > value NOT SET
4. $variable = 0 > value NOT SET
5. $variable = NULL > value NOT SET

any other examples?
Inparticular the 1. and 4. should be noted as I thought 1. would be NOT SET and 4. should be SET but it seems they are not through testing. Anyone confirm these as they dont seem logical to me?

Thanks, Regards X

PS: If anyone has anything else to add go ahead.

Thanks cwarn, http://php.net/manual/en/function.empty.php.
(How do you do the link brackets?)

The following things are considered to be empty:

* "" (an empty string)
* 0 (0 as an integer)
* "0" (0 as a string)
* NULL
* FALSE
* array() (an empty array)
* var $var; (a variable declared, but without a value in a class)

So I think using empty() instead of isset() is a better option?

Member Avatar for diafol

Re isset()
$variable = "" > value SET
This is different to NULL as it is technically a string - zero-length. To my mind NULL means not set/no value at all, so this equates to no definition. However just my thoughts.
A variable set to zero not showing up a set strikes me as odd as this should be a valid value. If this is true, can you unset a variable by setting the value to 0 as opposed to using unset()?

Oh, bugger. I've got a million scripts that use isset() checks. *Blood turns to ice*

I think the reason why 0 is not isset is because the binary value of zero is 00000000. So any variable/array with the binary value 00000000 is said to be not isset. That is why zero is unset.

commented: thanx for putting me straight on that +5
Member Avatar for diafol

I think the reason why 0 is not isset is because the binary value of zero is 00000000. So any variable/array with the binary value 00000000 is said to be not isset. That is why zero is unset.

Thanx C. *Frantically fumbling for a quick fix - there goes another weekend*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.