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