Function Parameter Default Value / Optional Parameter

Share Now

#Main PHP File

#Functions PHP File

***Important Notes:
You cannot write the code like this
If you give a default value to one parameter, you have to do it for the other one too.

function serve( $items="2",$food_name  ) {

echo "{$items} of {$food_name} has been served";

Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert