CodesJava

Easy learning with example program codes

PHP Parameterized Function


PHP Parameterized Functions are the PHP functions with parameters. PHP Parameterized functions are a piece of code that can be used repeatedly in a PHP program. Any number of parameters can be passed inside a parameterized function after the name of the function, inside the parentheses.

Syntax:

function functionName() 
{
    code to be executed;
}

Example 1: Parameterized Function used with a single argument

<!DOCTYPE html>
<html>
<body>
 
<?php
function website($languagename) {
	echo "$languagename.<br>";
}
 
website("PHP");
website("Jquery");
website("HTML");
website("Javascript");
?>
 
</body>
</html>

Output

PHP.
Jquery.
HTML.
Javascript.

Example 2: Parameterized function used for ADDITION (Two arguments passed; function returns a value)

<!DOCTYPE html>
<html>
<body>
 
<?php
function sum($x, $y) {
	$z = $x + $y;
	return $z;
}
 
echo "Sum of 4575 and 1890 = " . sum(4575,1890) . "<br>";
echo "Sum of 5677 and 1783 = " . sum(5677,1783) . "<br>";
echo "Sum of 268879 and 49879080 = " . sum(268879,49879080);
?>
 
</body>
</html>

Output

Sum of 4575 and 1890 = 6465
Sum of 5677 and 1783 = 7460
Sum of 268879 and 49879080 = 50147959
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