faqts : Computers : Programming : Languages : PHP : Common Problems : Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 10 people (100%) answered Yes
Recently 9 of 9 people (100%) answered Yes

Entry

How must I manage a variable that has either a value or doesn't exist at all.

Apr 19th, 2001 09:01
Mike Boucher, Andreas Pfeiffer,


Use the isset() function to be sure that the variable is set before 
using it in any functions that might cause an error.
if (isset($myVar))
{
    Do stuff with $myVar;
    Do more stuff with $myVar;
    Do something else with $myVar;
}
if you want to do something if the variable is not set you can use.
if (!isset($myVar))
{
    $myVar = "some default value";
}