welcome to tutorialfamily

php function

PHP Function – PHP has already made more than thousand of function.

You can create your own function manualy.


PHP function

PHP has pre build fuction but you can create your function with logic.

  • User Defined Function :
  • Function argument:

User Defined Function

A user-defined function declaration starts with the word function

Now we can create myFunction(), then ({) bracket are indicate the start the function code and (}) indicate close the function code.
After complete the code call the function.


User Defined Function



<!DOCTYPE html>
<html>
<head>
	<title>User Defined Function</title>
</head>
<body>
<?php
	function myFunction() {
		echo "Welcome to tutorialfamily";
	}

	myFunction(); // call the function
?>
</body>
</html>

output

PHP Function Arguments

An argument like is variable.

Pass the argument value to the function.

An argument passed inside the function name as a variable.

All argument value passed after the variable declare.

Below example: we have declare function with argument variable ($cname). Then declare the all argument value inside the function name.


PHP Function Arguments



<!DOCTYPE html>
<html>
<head>
	<title>PHP Function Arguments</title>
</head>
<body>
<?php
function carName($cname) {
    echo "$cname.<br>";
}

carName("Toyota");
carName("Honda");
carName("Verna");
carName("Versa");
carName("Oddi");
?>
</body>
</html>

output

Our Content