Looping through an array of 2500 items would defiantly use some CPU, but that doesn't mean that it isn't the most efficient way to go. Could you provide just a top level overview of what the elements in the array actually are? Their purpose and origin would determine if a database is the way to go or not.
They've essentially search terms which have "perfect" results pages already created.
If people search for these things, there is a specific page they want to go to.
There is an Apache httpd method which involves a lookup text file or script:
http://httpd.apache.org/docs/2.2/mod/mod_r...html#rewritemap
http://httpd.apache.org/docs/2.2/rewrite/r...ernal-rewriting
But you need root access to the server.
If you want to cut down on CPU usage, you can do some basic indexing: if the first letter is "a", only look at the "a" array, (etc for each letter/number). But that assumes an exact match which is far more efficient than a partial match. If you want partial matching, I think a database lookup (using LIKE on an indexed table) would be the way to go. But an index again will only work best for something like "abcd%" and not "%abcd%". It really depends on what sort of efficiency you need. If you can use some indexing it will make a huge difference, database or not.
PHP in_array() is probably the quickest way that I know of.
Hello.
I currently have an array of ~2500 items, each one of length about 10characters, just A-Za-z0-9, no extra characters.
Here's the pseudo-code of what I want:
{ redirect to "/path-to/$inputstring" }
else
{ redirect to "/different-path-to/$inputstring" }
I want to do this efficiently, so that it doesn't take up lots of CPU.
I don't mind putting them in an database if that would be better, at present the array is already sorted alpha-numerically.
I'm using php.
Thanks very much.