在 PHP 中,您可以使用关联数组:
someFunction(array(
"a" => 3243,
"b" => 2354,
"c" => 33453,
"d" => 324353,
"e" => 321243,
"f" => 321243,
"g" => 312243,
"h" => 321243,
))
或正在调用该函数的对象的属性(如果有意义的话)。PHPMailer 发送这样的邮件:
// instantiate the class
$mailer = new PHPMailer();
// Set the subject
$mailer->Subject = 'This is a test';
// Body
$mailer->Body = 'This is a test of my mail system!';
// Add an address to send to.
$mailer->AddAddress('foo@host.com', 'Eric Rosebrock');
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
它还有更多的可选参数。它也可以使用具有数百个参数的方法,但这更具可读性。
编辑:这些解决方案也更好地支持可选参数。在属性的情况下,它很简单,在关联数组的情况下,您可以将数组与默认值数组合并。