$Var1 = "item1";
$Var2 = "item2";
$Var3 = "item3";
print "Content-type: text/html\n\n";
&MySub($Var1,$Var2,$Var3);
sub MySub($something, $something2, $something3) {
print "Test! $something <p> $something2 <p> $something3";
}
sub MySub {
print "Test! $_[0] <p> $_[1] <p> $_[2]";
}
You can include a prototype to define the types and amounts of variables it can take, but you can't name them. For example:
sub MySub (\$\$\$){
print "Test! $_[0] <p> $_[1] <p> $_[2]";
}
($ instead of \$ will cast the arguments to scalors rather than throw an exception if the function is called with the wrong argument type.)
Shawn
($var1, $var2, $var3) = @_;
With PHP [php.net] you can use the func_get_args [php.net] function to get an array of passed variable as well. func_get_arg [php.net](arg_number) will return the argument at the arg_number th offset of the argument list. This is similar to Perl [perl.com]īs $_[arg_number].
Andreas