function validate($value, $reg) {
// ... тут валидация
return true;
}
$filterKey = array(
array(
'name' => 'code',
'validate' => '/^\d+$/'
),
array(
'name' => 'title',
'validate' => '/(.+?)/'
),
array(
'name' => 'color',
'validate' => '/^#?([a-f0-9]{6}|[a-f0-9]{3})$/'
)
);
$query = array();
foreach ($filterKey as $filter) {
if (validate($_GET[$filter['name']], $filter['validate'])) {
$query[] = array( $filter['name'] => $_GET[$filter['name']]);
}
}