06-16-2008, 12:09 AM
|
#7 (permalink)
|
|
The Gregarious
Join Date: Mar 2008
Location: Cana'derr
Posts: 653
Thanks: 24
|
Technically you could have an unlimited amount of optional arguments. The first way, and probably the least aesthetically pleasing would be to define a single argument and check if it's an array or not;
PHP Code:
function snuffleluffagus ($mArgs) {
if (is_array($mArgs)) { $intNumArgs = count($mArgs); // .. } else { // .. }
}
..and the second would use PHP's built in functionality, with func_num_args() and func_get_args().
PHP Code:
// example borrowed directly from PHP.net
function foo () {
$numargs = func_num_args(); echo "Number of arguments: $numargs<br />\n"; if ($numargs >= 2) { echo "Second argument is: " . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "Argument $i is: " . $arg_list[$i] . "<br />\n"; }
}
-m
|
|
|
|