php function default value – PHP supports passing arguments by value , passing by reference, and default argument values.
php function default value
PHP allows us to set default argument values for function parameters. Php: Set default value to function argument.
You can set default values to function parameters.
PHP Default Argument Values Function
Example 1
<!--?php <br ?--> function sayHowDoYouDo($name="Ram"){ echo "HowDoYouDo $name "; } sayHowDoYouDo("Meera"); sayHowDoYouDo();//passing no value sayHowDoYouDo("Vimal"); ?>
Results
HowDoYouDo Meera HowDoYouDo Ram HowDoYouDo Vimal
Don’t Miss : How to call function in PHP from another file?
Example 2
<!--?php <br ?--> function invitationcard($first="Kohali",$last="Sidhupura"){ echo "Welcome: $first $last "; } invitationcard(); invitationcard("Karshan"); invitationcard("Dhoni","Mahendrshinh"); ?>
Results
Welcome: Meera Sidhupura Welcome: Karshan Sidhupura Welcome: Dhoni Mahendrshinh
Example 3
<!--?php <br ?--> function add($n1=10,$n2=10){ $n3=$n1+$n2; echo "Calculation is: $n3 "; } add(); add(20); add(40,40); ?>
Results
Calculation is: 20 Calculation is: 30 Calculation is: 80
I hope you get an idea about php function default value.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.