[PHP] Re: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie
On 06/07/2011 12:45 PM, Floyd Resler wrote: What would be the easiest way to do a fuzzy array search? Can I do this without having to step through the array? Thanks! Floyd I use preg_grep() -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To

Re: [PHP] Re: Fuzzy Array Search

2011-06-07 Thread Alex Nikitin
If you don't need the location, you can implode the array and use preg match, quickly testing it, that gives you about 4.5 times performance increase, but it wont give you the location, only if a certain value exists within the array... You can kind of do some really clever math to get your search

Re: [PHP] Re: Fuzzy Array Search

2011-06-07 Thread Floyd Resler
On Jun 7, 2011, at 4:42 PM, Alex Nikitin wrote: If you don't need the location, you can implode the array and use preg match, quickly testing it, that gives you about 4.5 times performance increase, but it wont give you the location, only if a certain value exists within the array... You can

Re: [PHP] Re: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie
On 06/07/2011 03:57 PM, Floyd Resler wrote: On Jun 7, 2011, at 4:42 PM, Alex Nikitin wrote: If you don't need the location, you can implode the array and use preg match, quickly testing it, that gives you about 4.5 times performance increase, but it wont give you the location, only if a

Re: [PHP] Re: Fuzzy Array Search

2011-06-07 Thread Alex Nikitin
It runs fast on my 2.33 core 2, and about as fast on this small data set, on the dual 6 core with 96GB ram, or the 8 core 9GB box, it depends on the size of your data set, memory speed and latency, and miniscule amount of processing power (once again assuming small data set). That said, you could

Re: [PHP] Re: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie
On 06/07/2011 04:28 PM, Floyd Resler wrote: Shawn, I'm terrible with regular expressions. Could you give me an example? Thanks! Floyd Depends. Could be as simple as this to return an array of all occurrences of $needle in any of the $haystack_array values: $haystack_array =

Re: [PHP] Re: Fuzzy Array Search

2011-06-07 Thread Shawn McKenzie
On 06/07/2011 04:35 PM, Alex Nikitin wrote: Shawn, == is not good for string comparison, its a bad habit that one should get out of, use ===, its much safer . Yes, except that I was comparing a string to an array of integers :) Also try the same algorithm on 10 arrays of some number of