[thelist] Filtering an array in PHP for multiple criteria

Stephen Rider evolt_org at striderweb.com
Sun Jun 22 17:48:06 CDT 2008


On Jun 11, 2008, at 12:59 PM, Aaron Vegh wrote:

> Hi Matt,
>
>> Have you tried just looping through that array and doing a test on
>> category and toe values?
>
> Thanks for writing. Unfortunately that technique -- while brutishly
> simple :-) -- doesn't account for one thing I didn't mention: the
> search criteria are optional. So there may not be a value for toe
> type, for example, in which case the if statement would always fail.
> Neat thought, though; I hadn't considered it myself!


I would drop the various search criteria into an array -- but it's  
only added if there is a value there.  Then loop through the catalog,  
and for each catalog item, loop through the criteria array.  That way  
the catalog is only checked against criteria that actually have values.

Stephen



More information about the thelist mailing list