我有一個foreach循環,可以回顯用戶從複選框中做出的所有選擇。將foreach循環的輸出存儲到一個變量中
我想將值存儲到名爲$getCentralArea
的變量中。但是,當我回顯$getCentralArea
時,它顯示4
- 只顯示所選複選框的最後一個值。我應該得到的正確值是1,2,3,4
。
if(!empty($_POST['centralArea']))
{
foreach($_POST['centralArea'] as $centralArea)
{
$getCentralValue = $centralArea.","; //Output will be in the following format 1,2,3,4
}
}else{ $getCentralArea="";}
使用這種$ getCentralValue打印出來= $ centralArea 「」。用於字符串或創建數組。 –
使用$ getCentralValue []創建所有元素的數組。 –