PHP Advanced Series 2 - PHP Functions
PHP Advanced Series 2 - PHP Functions
PHP Functions
Overview
repetitive processes are likely to exist
For example:
in an e-commerce application, you might need to query a
customer’s profile information numerous times: at login, at
checkout, and when verifying a shipping address
repeating the profile querying process throughout the application
would be not only error-prone, but also a nightmare to maintain
if a new field has been added to the customer’s profile, You might
need to shift through each page of the application, modifying the
query as necessary, which would likely introducing errors in the
process
<?php
$value = pow(5,3); // returns 125
echo $value;
?>
If you want to display the output of the function within a larger string,
you need to concatenate it like this:
Output:
<p>Copyright © 2005 W. Jason Gilmore</p>
function salestax($price,$tax) {
$total = $price + ($price * $tax);
echo "Total cost: $total";
}
function salestax($price,$tax=.0575) {
return $price + ($price * $tax);
}
Here’s an example of how you would call this function:
<?php
$price = 6.50;
$total = salestax($price);
?>
Name: Jason,
email: jason@example.com,
preferred language: English