“The function is a set of instructions that are used to perform specific tasks/objectives”. It is useful for increasing the reusability of code.

As per its definition – Two  types

  • Predefined
  • User Defined

As per its structure – Four  types

SN Function Type Argument Return Type
1 No Argument, No Return Type No No
2 With Argument, No Return Type Yes No
3 With Argument, With Return Type Yes Yes
4 No Argument, With Return Type No Yes

No Argument, No Return Type

function sum(){
    $a=12;
    $b=13;
    $c=$a+$b;   
    echo "My Result = ".$c;
}

With Argument, No Return Type

function sum($a,$b){ 
    $c=$a+$b;   
    echo "My Result = ".$c;
}

With Argument, With Return Type

function sum($a,$b){ 
    $c=$a+$b;   
    return $c;
}

No Argument, With Return Type

function sum(){ 
    $a=12;
    $b=13;
    $c=$a+$b;   
     return $c;
}