Function in php Reviewed by Momizat on . function is a sub-routine or small program.which is design to perform to specific task. Examples [php] <?php /* syntax of function function functionname(){ / function is a sub-routine or small program.which is design to perform to specific task. Examples [php] <?php /* syntax of function function functionname(){ / Rating: 0

Function in php

function is a sub-routine or small program.which is design to perform to specific task.

Examples

<?php
/*
syntax of function
function functionname(){
 //statements.......
}
*/
// 1 ) create a function without parameter and no return
function add2num(){
echo (4+5);
}

//call add2num function

add2num(); //output 9

//2) create a function without parameter and return
function add2num(){
return (4+5);
}

//call add2num function

echo add2num(); //output 9

//3) create a function with parameter and no return
function add2num($a,$b){
echo  ($a+$b);
}

//call add2num function
add2num(4,5); //output 9

//4) create a function with parameter and return
function add2num($a,$b){
return ($a+$b);
}

//call add2num function

echo add2num(4,5); //output 9

?>

Leave a Comment

© 2014 Powered By