PHP tutorial-Function |
||||||||||||||
PHP FunctionA function that does not return a valuefunction function_name(){ statements; } Note: the name of function must start with a letter or underscore not a number Example: <html> <body> <?php //defining function:printHello function printHello(){ echo "Hello"; } //calling the function:printHello printHello(); ?> </body> </html> A function that returns a valuefunction function_name(){ statements; return value; } Example: <html> <body> <?php //defining function: sum function sum(){ $s=10+20; return $s; } //calling the function: sum $total=sum(); echo "Total=".$total; ?> </body> </html> Function parametersParameters are values to be passed to the function. Example: <html> <body> <?php //defining function:printName function printName($name){ echo "Hello ".$name; } //calling the function:printName printName("Khorn Channa"); ?> </body> </html> |
| |||||||||||||
|
||||||||||||||