我有一個像$a = array("A", "B", "C");我已經使用多項選擇將值存儲在數據庫中。保存的值"B", "C"在 2 個不同的行中我需要在同一個多選框中顯示選定的值"b"和值。"D"這里艱難的概念是我需要從數組中顯示選擇選項的值,如下所示 foreach($dbRows as $dbRow) { // here if i display the selected values using if condition the value are selected by the array values repeats like a - no selected b - selected c - no selectedagain loops repeats like a - no selected b - no selected c - selected }}如何在不重復的情況下顯示值?
1 回答

Cats萌萌
TA貢獻1805條經驗 獲得超9個贊
您可以循環選擇框數組并使用in_array()檢查它的值是否在 DB 數組中
$a = array("A", "B", "C");
foreach($a as $v)
{
$selected = in_array($v, $db_array) ? 'selected' : '';
}
- 1 回答
- 0 關注
- 83 瀏覽
添加回答
舉報
0/150
提交
取消