How to use Functions in php

PHP

We will show you a simple example how to use the Function in php. Function is used to run the code with multiple time. You can use a single function many times with the help of parameters and return value you can use a single function in many times and in many ways.You may call a function from anywhere within a page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Functions Examples in PHP</title>
</head>
<body>
<?php
// A simple example with out the parameters

//This way you can create the function
function login()
{
//You can write what ever you want to write in the function
echo 'Welcome User X.';
}
//By this way you can call the function and the function inner content will be called as many time as you will call this function
login();

//Lets Take example with one parameter

function login_parameter($user)
{
echo 'Welcome User'.$user;
}
//X is passed as a parameter and then it will be used in the function
login_parameter('X');

//Lets Take example with two parameter but second parameter value is not fix

//if there will be no second parameter then also this function will work and by default second parameter value is taken as blank
function login_twopara($firstname,$lastname='')
{
echo $firstname.$lastname;
}
login_twopara("John");

?>
</body>
</html>
-->