Sometimes we need one set of code more than one time, at that point of time function helps us a lot. A function is a set of coding within a block, which has a specific name, could have few arguments, and a return data type.
With the help of functions we can reduce time and effort, all we need to do is create a function and put the necessary coding into it and we can call this function from anywhere of the program.
One function can be called number of times, and one function can call itself too, this technique is called recursion.
Example:
<?php
function add($a,$b){ return $a+$b;} $c=add(12,39); echo "Addition is:".$c;?>
Output:
Addition is:51
Example:
<?php
function fact($b){ if($b==1) return 1; elsereturn
($b* fact($b-1));}
echo "Factorial of 6 is:".fact(6);?>
Output:
Factorial of 6 is:720
More PHP Functions with examples
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.