A function returns a value of FALSE when there's an error in a function. One way to handle this return FALSE is to use the PHP die function.
Here is reciprocal.php that has a FALSE return value..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php function reciprocal($value) { if ($value !=0) { return 1/$value; } else { return FALSE; } } ?> </p> </body> </html> |
Here is the script calling the reciprocal function.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>PHP</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php include('reciprocal.php'); echo reciprocal(0) or die("There is no reciprocal for 0."); ?> </p> </body> </html> |