PHP
June 3, 2026 1 min read

PHP Functions: Creating and Utilizing Functions for Efficient Programming

HS
HEMANT SINGH
Technical Writer & Educator

When we have repetitive work for example we have a project where we need to calculate factorial of a number many times, so to calculate factorial of number every time there will be very helpful to create that program(factorial of a program) in a separate place that is called a function.

actually is a block of the statement which executes every time when the function is called.

In PHP, functions are created using the function keywords.

Basic PHP function

function printName(){
echo "Aman kumar";
}
printName();

function argument

function printFatherName(){
echo "Rakesh kumar";
}
printFatherName();

default argument

function sum($x=0, $y=0){
$z=$x+$y;
echo "sum:$z";
}
sum();
sum(10,20);

returning value

function areaCircle($r=1){
return 3.14*$r*$r;
}
$area=areaCircle();
echo $area;
$area=areaCircle(5);
echo $area;