可以在 PHP 的 filter_input() 篩選器標誌中組合 AND/OR 嗎?
是的,PHP 中可以將 filter_input() 與 AND/OR 結合使用。這可以透過迴圈訪問 POST 欄位來實現−
$value = filter_input(INPUT_POST, 'field', FILTER_DEFAULT, is_array($_POST['field']) ? FILTER_REQUIRE_ARRAY : NULL);
下面展示了每個迴圈中相同使用者的一個等價項−
$memory = array(); //looping through all posted values foreach($_POST as $key => $value) { //applying a filter for the array if(is_array($value)) { $ memory [$key] = filter_input(INPUT_POST, $key, {filters for array}); } else { $ memory [$key] = filter_input(INPUT_POST, $key, {filters for scalar}); } }
廣告