Which is the correct method for defining a function in PHP
- function myFunction($arg_n) { return $retval; }
- Function myFunction(p1) myFunction = (p1 - 32) End Function
- int myFunction(int p1) { return p1; }
- function myFunction(p1, p2) { return p1 * p2; }
EXPLANATION
Its very easy to create your own PHP function. Suppose you want to create a PHP function which will simply write a simple message on your browser when you will call it. Following example creates a function called writeMessage() and then calls it just after creating it.
Note that while creating a function its name should start with keyword function and all the PHP code should be put inside { and } braces as shown in the following example below −
<?php /* Defining a PHP Function */ function writeMessage() { echo "You are really a nice person, Have a nice time!"; } /* Calling a PHP Function */ writeMessage(); ?>
For more information check out: http://php.net/manual/en/functions.user-defined.phpThe other answers and their language is below:
function myFunction(p1, p2) { return p1 * p2; } is JavaScript
Function myFunction(p1) myFunction = (p1 - 32) End Function is VBScript
int myFunction(int p1) { return p1; } is C