Functions [June 16, 2011, 2:01 p.m.]
Functions allow us to reuse bits of code. For example, say that we are calculating tax on transactions. We can wrap up our code in a functional unit and give it a name:
<?php
function calculate_tax($price, $tax) {
$sales_tax = $price *$ tax;
$total = $price + $sales_ tax;
return $total;
}
?>
From then on we can just call that name and pass it some information (called arguments):
calculate_tax("53", "0.075")
This will save us time as well as make our code easier to review. Lets take a look at some more in-depth learning resources.
Recursion Function
Taken from php.net
<?php
function recursion($a)
{
if ($a < 20) {
echo "$a\n";
recursion($a + 1);
}
}
?>