VOOZH about

URL: https://www.geeksforgeeks.org/php/how-to-create-default-function-parameter-in-php/

⇱ How to create default function parameter in PHP? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to create default function parameter in PHP?

Last Updated : 12 Jul, 2025

The default parameter concept comes from C++ style default argument values, same as in PHP you can provide default parameters so that when a parameter is not passed to the function. Then it is still available within the function with a pre-defined value. This function also can be called optional parameter

Syntax:

function greeting($name=" parameter_value ")

Parameter: This function accepts a single parameter that is $name here, holds the parameter value. 

Below examples illustrate the procedure to create and use the default function parameter.

Example 1: 

Output:

Welcome to Gfg 
Welcome to GeeksforGeeks 
Welcome to A Computer Science Portal 

Example 2: 

Output:

Greeting: GeeksforGeeks A Computer Science Portal for Geeks
Greeting: night_fury A Computer Science Portal for Geeks
Greeting: night_fury Contributor
Comment
Article Tags: