Function helps in reusability of code. Function is generally used instead of repeating code.
For Example;
<?php
function fullName ($first){
echo "Johnson".$first;
}
// End of function
// calling of function begins
fullName (Ola);
//output will be Johnson Ola
fullName (Soji);
//output will be Johnson Soji
?>
Another example is cited below;
Find area of CIRCLE using PHP
<?php
function myCircle($r){
$a = 3.142 * $r * $r;
echo "The area of circle is:" . $a;
}
// End of function
// calling of function begins
myCircle(10);
?>
Note: After function name is parenthesis “( )” , inside parenthesis is argument.
Arguments are the ingredients or variables that are inside the parenthesis , the number of argument must be equal to the number of parameter i.e. if argument is two, parameter must be two. And it must be corresponding to each other i.e. if the first augment is $length, the first parameter must be length value For example;
<?php
function fullName($first, $middle){
echo "Ade"."".$first."".$middle;
}
// End of function
// calling of function begins
fullName(Enzo, Onana);
?>
//output will be Ade Enzo Onana
PREDEFINED FUNCTION IN PHP
Predefined Functions simply means using an existing function inside your code.
For example;
Strlen ()
</php
$word = Education;
$count = strlen($word);
// End of function
// calling of function begins
echo $count;
?>
Outcome in the code above will be 9
OR
<?php
function solarexFxn ($name){
$count = strlen ($name);
echo "The letters in the word is ".$count;
echo "br";}
// End of function
// calling of function begins
solarexFxn (Education);
?>
Outcome will be:
The letters in the word is 9
solarexFxn (Ability);
Outcome will be:
The letters in the word is 7
solarexFxn (pismapisma);
Outcome will be:
The letters in the word is 10
This concludes our lecture on PHP Function.
READ MORE ON VARIABLE SCOPE TO LEARN MORE ABOUT FUNCTION



