Filter()
Filter(array $haystack, string $needle, string|boolean $key = false, array $options = array()) : array
Filters an array based on a query
Passing an empty query ($needle) to this method will simply return the initial array.
If you have fold
on, then this will fail on characters that cannot be translitered
into regular ASCII, so most Asian languages.
The options to be set are:
- max_results -- the maximum number of results to return (default: false)
- min_score -- the minimum score to return (0-100) (default: false)
- return_score -- whether or not to return the score along with the results (default: false)
- fold -- whether or not to fold diacritical marks, thus making
über
intouber
. (default: true) -
match_type -- the type of filters to run. (default: MATCH_ALL)
The match_type is defined as constants, and so you can call them by the flags or by the integer value. Options: Match items that start with the query 1: MATCH_STARTSWITH Match items whose capital letters start with
query
2: MATCH_CAPITALS Match items with a component "word" that matchesquery
4: MATCH_ATOM Match items whose initials (based on atoms) start withquery
8: MATCH_INITIALS_STARTSWITH Match items whose initials (based on atoms) containquery
16: MATCH_INITIALS_CONTAIN Combination of MATCH_INITIALS_STARTSWITH and MATCH_INITIALS_CONTAIN 24: MATCH_INITIALS Match items ifquery
is a substring 32: MATCH_SUBSTRING Match items if all characters inquery
appear in the item in order 64: MATCHALLCHARS Combination of all other ``MATCH*`` constants 127: MATCH_ALL
Parameters
array | $haystack | the array of items to filter |
string | $needle | the search query to filter against |
string|boolean | $key | the name of the key to filter on if array is associative |
array | $options | a list of options to configure the filter |
Returns
array —an array of filtered items