<?php#Syntax:functionfunctionName(){
code to be executed;}functionGreetings(){echo"Hello, welcome!";}Greetings();#Execute function #Function arguements#Function arguements are just like prefixes/suffixes and can have multiple arguementsfunctionPolygon(str$prefix= penta,str$suffix= gon){echo"$prefix$suffix"}Polygon("tetra","gon");Polygon();#Here, we use default valuePolygon("hexa","gon");Polygon("septa","gon");?>
// functions require 'function' keyword// separate the parameters with a commafunctionaddFunction($num1,$num2){$sum=$num1+$num2;echo"Sum of the two numbers is : $sum";}addFunction(1,2);// echoes: Sum of the two numbers is : 3
<?phpfunctionfoo(){$numargs=func_num_args();echo"Number of arguments: $numargs
";if($numargs>=2){echo"Second argument is: ".func_get_arg(1)."
";}$arg_list=func_get_args();for($i=0;$i<$numargs;$i++){echo"Argument $i is: ".$arg_list[$i]."
";}}foo(1,2,3);?>
<?php#Syntax:functionfunctionName(){
code to be executed;}functionGreetings(){echo"Hello, welcome!";}Greetings();#Execute function #Function arguements#Function arguements are just like prefixes/suffixes and can have multiple arguementsfunctionPolygon(str$prefix= penta,str$suffix= gon){echo"$prefix$suffix"}Polygon("tetra","gon");Polygon();#Here, we use default valuePolygon("hexa","gon");Polygon("septa","gon");?>
// functions require 'function' keyword// separate the parameters with a commafunctionaddFunction($num1,$num2){$sum=$num1+$num2;echo"Sum of the two numbers is : $sum";}addFunction(1,2);// echoes: Sum of the two numbers is : 3
<?phpfunctionfoo(){$numargs=func_num_args();echo"Number of arguments: $numargs
";if($numargs>=2){echo"Second argument is: ".func_get_arg(1)."
";}$arg_list=func_get_args();for($i=0;$i<$numargs;$i++){echo"Argument $i is: ".$arg_list[$i]."
";}}foo(1,2,3);?>