PHP Functions Examples
In PHP, a function is defined using the
function command. This is followed by a space,
the function name, and parentheses.
See an example of such a function:
<?php
function func()
{
return 'text';
}
echo func(); // will output 'text'
?>
Parameters can also be passed to a function.
Look at an example of a function that will take a number as a parameter and return its square:
<?php
function func($num)
{
return $num * $num;
}
echo func(2); // will output 4
echo func(3); // will output 9
?>