$var_test = 0;
var_dump($var_test);
if($var_test){
echo('does Not work');
}
if(isset($var_test)){
echo('will Work');
}
if(isset($_POST['submit'])) {
echo "submit\n";
}
echo "Hi";
$var = false;
unset($var);
echo isset($var) ? $var : 'no exist';
echo $var? $var : 'no exist';
<?php
$a = null;
$b = false;
$c = 0;
if(isset($a)) {
echo "1";
echo "<br /-->";
var_dump($a);
echo "<br>";
}
if(isset($b)) {
echo "2";
echo "<br>";
var_dump($b);
echo "<br>";
}
if(isset($c)) {
echo "3";
echo "<br>";
var_dump($c);
echo "<br>";
}
if(isset($d)) {
echo "4";
echo "<br>";
var_dump($d);
echo "<br>";
}
Find more questions by tags PHP
For this there is is_null().
The main purpose of isset is to check if a variable exists in principle, for example, in order not to override. - Clementina_Jacobs commented on July 9th 19 at 10:54
Is input(button) which when clicked will define a blank line ( I don't know what returns the button,but apparently an empty string).And it turns out that without isset() in the if will be FALSE (because FALSE accepts an empty string too) and a script inside the if will not run.And if you use isset () will return TRUE and it will work.
And is_null() in the manual will also return FALSE, and again, the script will not run.
Maybe I'm confused and don't understand - rylan commented on July 9th 19 at 10:57
$var_test = NULL;
var_dump($var_test);
if($var_test){
echo('does Not work');
}
if(isset($var_test)){
echo('will Not work');
}
if(is_null($var_test)){
echo('will work');
} - Juana95 commented on July 9th 19 at 11:00
$var = false;
unset($var);
echo isset($var) ? $var: 'no exist';
echo $var? $var: 'no exist'; - Clementina_Jacobs commented on July 9th 19 at 11:03
Quote from php.net In the case of an uninitialized variable is called the error of level E_NOTICE, except in the case of adding elements to uninitialized array. For the detection of initialization of a variable can be used by the language construct isset(). End quote.
In your case the output of E_NOTICE is suppressed by settings php on a different server with different settings of the emergence of heaps of warnings can become an unpleasant surprise and, in some cases, even break the script. In very active scripts is inevitable, the expansion of the log - rylan commented on July 9th 19 at 11:06