0
我有以下代码...将项目推送到PHP数组的末尾?
if ($email_selection == "primary") {
$default_select = "<option value=''>Select Email</option>";
$select_1 = "selected";
$to_array[] = $profile_primary_email;
} elseif ($email_selection == "secondary") {
$default_select = "<option value=''>Select Email</option>";
$select_2 = "selected";
$to_array[] = $profile_primary_email;
} elseif ($email_selection == "both") {
$default_select = "<option value=''>Select Email</option>";
$select_3 = "selected";
$to_array[] = $profile_primary_email . ',' . $profile_secondary_email;
}
if ($manual_email != "") {
$to_array[] = $manual_email;
}
$to_array_count = count($to_array);
$to = $to_array["0"];
for ($v = 1; $v < $to_count; $v++) {
$to = $to . ',' . $to_array[$v];
}
这段代码的作用是让一个选择输入的值,并基于选择输入的值推一个电子邮件地址的$to_array
末。然后脚本将每个电子邮件的字符串用逗号分隔,稍后将用作PHP mail()
函数中的$to
。
由于某些原因,选择字段包含任何值,$manual_email
中包含的电子邮件地址不会附加到该数组。但是,如果选择字段没有值,则通常将$manual_email
附加到空数组。
'$ to_array [0]'和'$ to_array ['0']'在PHP中不一样。 – PHPglue
删除或添加引号不会更改脚本的功能。我一直使用它们互换,并且很好。无论如何,我也有同样的问题。 – Allenph
只是为了澄清最后一段,如果'$ to_array'包含一些数据,你是否在说'$ manual_email'没有被追加? – khuderm