CodesJava

Easy learning with example program codes

PHP Default Arguments


If we call a PHP function without arguments, PHP functions takes the default value as an argument, just like in C++.
Example 1: Code for Default Argument for a function with a single argument.

<!DOCTYPE html>
<html>
<body>
 
<?php
function weight($defaultweight = 60) {
	echo "The weight is : $defaultweight <br>";
}
weight(45);
weight();
weight(70);
weight(80);
?>
 
</body>
</html>

Output

The weight is : 45
The weight is : 60
The weight is : 70
The weight is : 80

Example 2: Code for Default Argument for a function with more than one argument.

<!DOCTYPE html>
<html>
<body>
 
<?php
function hw($weight = 60, $height = 5) {
	echo "The height and weight is : $height, $weight<br>"; 
}
hw(45,4);
hw();
hw(70,6);
hw(80,5);
?>
 
</body>
</html>

Output

The height and weight is : 4, 45
The height and weight is : 5, 60
The height and weight is : 6, 70
The height and weight is : 5, 80
Posted in PHP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki