hide sting if variable is null

I need help making something like this.

so for example


if ($number == NULL) {
echo 'there is a $number';
}
else {
echo 'There is no value';
}

i think i figured it out
Is this correct?

if (isset($number))
{
   echo "Variable is set";
}  
else
{
echo "its not set";
}

[php]

if (!empty($number))
echo ‘there is a $number’;
}
else {
echo ‘There is no value’;
}
[/php]
or if you want to check if empty versus not empty
[php]
if (empty($number))
echo ‘There is no value’;
}
else {
echo ‘there is a $number’;
}
[/php]

try that please dont use isset empty is better

Thanks alot !Perfect

empty and isset are two different things and which one to use depends on your needs.

using isset($number) will return true if $number is set, but equal to 0, 1, 2, etc.
using empty($number) will return true (empty) if your value is 0 and false if your number is 1, 2, 3, etc.

Lets say you have a form that asks a user to enter a temperature to convert from Fahrenheit to Celcius. If you check for input by using empty and the user entered 0 degrees, your code will not execute with a check for empty, but it will with isset.

You originally wanted to check for a NULL value. In this case, you should use ($number === NULL).

Hope this makes sense

you are welcome

Sponsor our Newsletter | Privacy Policy | Terms of Service