Filtering an array
Posted: Tue Apr 22, 2008 5:09 pm
I've come to a brick wall in my script that I'm writing and I wondered why I couldn't find a php function that simply did this:
(This is the build up to the function):
Grab an array of data from a mysql database, it is multi-dimensional as the first 'layer' contains each row and each row then contains the data for the row in an array.
Then (this is what the function should do):
Search the array of data from the mysql table for a string (this could occur in the second layer so this should also be searched) and then return only the rows of the array which contain the string in array format.
The closest I could find was array_filter(), but it requires a function for each filter which I can't do because I'm carrying out hundreds of different filters on the same original array. I can't use mysql to filter the results (using a new query for each filter) as this would be extremely innefficient.
If someone has written a function which does this or knows of one that exists could they please help me out?
I'd be really grateful.
Thanks
(This is the build up to the function):
Grab an array of data from a mysql database, it is multi-dimensional as the first 'layer' contains each row and each row then contains the data for the row in an array.
Then (this is what the function should do):
Search the array of data from the mysql table for a string (this could occur in the second layer so this should also be searched) and then return only the rows of the array which contain the string in array format.
The closest I could find was array_filter(), but it requires a function for each filter which I can't do because I'm carrying out hundreds of different filters on the same original array. I can't use mysql to filter the results (using a new query for each filter) as this would be extremely innefficient.
If someone has written a function which does this or knows of one that exists could they please help me out?
I'd be really grateful.
Thanks