Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,425 questions

16,935 answers

573 users

How to determine if a variable is set and is not NULL in PHP

8 Answers

0 votes
$var = '';

if (isset($var)) 
    echo "yes";


/*
run: 

yes  

*/

 




answered Jul 2, 2016 by avibootz
0 votes
$var = 'PHP';

var_dump(isset($var));


/*
run: 

bool(true)   

*/

 




answered Jul 2, 2016 by avibootz
0 votes
var_dump(isset($var));


/*
run: 

bool(false)   

*/

 




answered Jul 2, 2016 by avibootz
0 votes
$var;

var_dump(isset($var));


/*
run: 

bool(false)   

*/

 




answered Jul 2, 2016 by avibootz
0 votes
$var = "PHP";
var_dump(isset($var));

echo "<br />";
unset($var);
var_dump(isset($var));

/*
run: 

bool(true) 
bool(false) 

*/

 




answered Jul 2, 2016 by avibootz
0 votes
$var = null;
var_dump(isset($var));

/*
run: 

bool(false)  

*/

 




answered Jul 2, 2016 by avibootz
0 votes
$arr = array('aaa' => 1, 'bbb' => NULL);

echo "<pre>";
var_dump(isset($arr['aaa']));        
var_dump(isset($arr['bbb']));       
var_dump(isset($arr['ccc']));          
echo "</pre>";

/*
run: 

bool(true)
bool(false)
bool(false)

*/

 




answered Jul 2, 2016 by avibootz
0 votes
$s = 'PHP Startup or PHP start-up';

echo "<pre>";
var_dump(isset($s['PHP Startup or PHP start-up'])); // false
var_dump(isset($s['PHP'])); // false
var_dump(isset($s[0])); // true
var_dump(isset($s['0'])); // true
var_dump(isset($s[0.7])); // true
var_dump(isset($s['0.7'])); // false
var_dump(isset($s['0 PHP'])); // false
echo "</pre>";

/*
run: 

bool(false)
bool(false)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)

*/

 




answered Jul 2, 2016 by avibootz
...