I am really confused about how I should approach/implement a filter feature.
So I am a simple checkbox with 4 values: val1, val2, val3, val4 which has to act like a category filter. If user selects val1 and val3 will show results only from that category.
Ok so the problem is how should I implement this feature in the backend. I think the best idea would be to use a switch function but the problem is that $filterData brings values in this format: val1,val3,val4 so a switch and a case would work.
I was thinking of trying to implode it using ‘,’ as a glue but from what I have tried I didn’t succeed until now.
It should work something like this
switch ($filterData)
{
case 'Values of filter data' (ex: val3 and val4 ):
$result[$value.'Results'] = $this->_$value($data);
break;
}
return $result;
I have tried to do a
$filterData = implode(',',$filterData);
foreach ($filterData as $key => $value)
{
switch ($value){
case $value:
$result[$value.'Results'] = $this->_$value($data);
break;}
}
but the problem is that this will return this:
Array
(
[value1Results] => value1
)
Array
(
[value1Results] => value1
[value2Results] => value2
)
Array
(
[value1Results] => value1
[value2Results] => value2
[value3Results] => value3
)
Any ideas how to implement/fix this?
Ok, here is the solution that works for me