10

我知道有很多关于这方面的文档,但是这一行代码花了我很长时间才在一个 4000 行的文件中找到,我希望第一次尝试就正确。

file_put_contents($myFile,serialize(array($email_number,$email_address))) or die("can't open file");
    if ($address != "email@domain.com") {
        $email['headers'] = array('CC' => 'email@domain.com');
    }
}

在此 if 语句之后,我基本上想添加

'BCC' => 'another_email@domain.com'

$email['headers']数组中(因此无论 if 评估为真与否,它都会添加它)

4

3 回答 3

26

您可以像这样单独添加它们:

$array["key"] = "value";

总而言之,像这样:

$array = array(
    "key"  => "value",
    "key2" => "value2"
);

或者您可以合并两个或多个数组array_merge

$array = array( "Foo" => "Bar", "Fiz" => "Buz" );

$new = array_merge( $array, array( "Stack" => "Overflow" ) );

print_r( $new );

这导致新闻键/值对被添加到旧的:

大批
(
  [Foo] => 酒吧
  [Fiz] => 布兹
  [堆栈] => 溢出
)
于 2012-05-30T05:25:15.607 回答
2

你可以这样做:$email['headers']['BCC'] = "Test@rest.com" 但你需要在 if 之后添加它。

于 2012-05-30T05:24:52.733 回答
0
$email['headers'] = array();

if ($address != "email@domain.com") {
   $email['headers']['CC'] = 'email@domain.com';
}

$email['headers']['BCC'] = 'another_email@domain.com';
于 2012-05-30T05:24:25.180 回答