How to use Functions in 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" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Functions Examples in PHP</title>
// 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

//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

//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;