} else {
echo "Name was not set";
}
if (isset($name)) {
echo "Name was set to $name\n";
unset($name);
} else {
echo "Name was not set";
}
?>
This script runs the same isset() check twice, but it uses unset() on the
variable after the first check. It therefore prints “Name was set to
Ildiko” and then “Name was not set”.
Perhaps the most frequently used function in PHP is exit, although purists
will tell you that it is in fact a language construct rather than a function. exit
terminates the processing of the script as soon as it is executed, which means
subsequent lines of code are not executed. That is really all there is to it; it
barely deserves an example, but here is one just to make sure:
Click here to view code image
<?php
exit;
echo "Exit is a language construct!\n";
?>
This script prints nothing because the exit comes before the echo.
One function we can guarantee you will use a lot is var_dump(), which
dumps out information about a variable, including its value, to the screen.
This function is invaluable for arrays because it prints every value and, if one
or more of the elements is an array, it prints all the elements from those, and
so on. To use this function, just pass a variable to it as its only parameter, as
shown here:
Click here to view code image
<?php
$drones = array("Graham", "Julian", "Nick", "Paul");
var_dump($drones);
?>
The output from this script looks as follows:
Click here to view code image
array(4) {
[0]=>