PHP allows you to define C++ style default argument values. In such case, if you don’t pass any value to the function, it will use default argument value.

Let’ see the simple example of using PHP default arguments in function.

Example 1

";  
}  
sayHello("Sonoo");  
sayHello();//passing no value  
sayHello("Vimal");  
?>

Output:

Hello Sonoo
Hello Ram
Hello Vimal

Example 2

";    
}    
greeting();  
greeting("Rahul");  
greeting("Michael","Clark");  
?>

Output:

Greeting: Sonoo Jaiswal
Greeting: Rahul Jaiswal
Greeting: Michael Clark

Example 3

";  
}  
add();  
add(20);  
add(40,40);  
?>

Output:

Addition is: 20
Addition is: 30
Addition is: 80