Home Apache PHP Ubuntu MySQL Linux HTML Win CSS Perl Javascript Rants Retro
 
Print This Page
Date Posted: Saturday 26th of November 2011 | Category: PHP
PHP functions. How do I create a php function.
Here is a basic function in php. The function takes two numbers and returns the total.

Functions come in handy when you are going to be reusing the code many times in your website.

Example, you had 10 bits of the same code scattered around your site, and instead of adding the two numbers you are required to multiply them. Its just a simple case of changing the one function.

To make things even easier, so that you don't need to include the function code every time you wish to run it, you could include this in a php include file.

<?php
function calculate($a,$b)
{
$total = $a + $b;
return $total;
}

echo calculate(10,2);
?>