Changes

An Introduction to PHP Variables

886 bytes added, 17:26, 25 May 2007
Checking Whether a Variable is Set
== Checking Whether a Variable is Set ==
 
When working with variables it is often necessary to ascertain whether a variable actually has a value associated with it or not at any particular point in a script. A mechanism is provided with PHP provide this ability through the ''isset()'' function. To test whether a variable has a value set simply call the 'isset()'' function passing through the name of the variable as an argument (see [[PHP Functions]] for details of passing through arguments to functions. The following code example tests to see if a variable has a value or not and displays a message accordingly:
 
<pre>
<?php
 
$myVariable = "hello";
 
if (isset($myVariable))
{
echo "It is set.";
}
else
{
echo "It is not set.";
}
?>
</pre>
 
If you are unfamiliar with using ''if'' statements in programming and scripting languages don't worry - we will cover them in the [[PHP Looping and Flow Control]] chapter.