Page 93 - Open Soource Technologies 304.indd
P. 93
Unit 4: Functions
So, a quick tips for you. You could actually have several return values inside a function. You Notes
could have it like this:
<?php
function multiple_return($val2, $val2){
if this happens{
return this value;
}
if that happens{
return this value;
}
}
?>
You could even have a function that had dozens of return value in it and a final return value at
the very end of the function so that if none of the others were true, none of the others happen,
then it would return something like FALSE or a DEFAULT value.
Of course if we are returning a value, then we also have to receive (or catch) the value at the other
end. Unlike say_hello() function where we called it on it is own.
Example:
<?php
function say_hello($word){
echo “Hello {$word}!”;
}
say_hello(“Everyone”);
?>
we set it to the variable $returned_value so we can echo it back.
<?php
$returned_value = overtime(2000,24,8, 1.5);
echo $returned_value;
?>
The next return value tips that we want to tell you about is that return one and only one value.
If you need to return more than one value, there is a way to do that.
Function with more than One Return Values
For this, let me explain in a new example.
Example:
<html>
<head>
<title>Writing Functions In PHP Return Values</title>
LOVELY PROFESSIONAL UNIVERSITY 87