If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Have you ever tried the "count_chars" PHP function before NogDog? It could possibly replace your ranged query builder.

I used it for populating the table and building the query, but decided to then let the database do the brute force work while being able to make use of all the indexes to optimize it. However, a few years ago I made an anagram solver that actually stored a serialized version of the count_chars() result in the database, then all I had to do was apply count_chars() to the input word, serialize() it, and look for that in the DB: http://charles-reace.com/PHP_and_MySQL/Anagram_Finder/ (don't laugh too much when you look at it: I haven't updated that site in a lonnngggg time).

BTW, what is the point converting 'a-z' to integer value, then building an array with integer keys, only to convert them back to chars. Why not just use an array with string keys?

As to why, because count_chars() creates its resulting array with the numeric byte-values as the keys. Now, whether or not it would have made more sense at that point to immediate covert them to the corresponding characters would have made more sense, you might have a point -- or not: I've obviously not thought it through completely.

Well one thing you can be sure of is the key order. With an associative array the keys could be in any order. If you were going to serialize and compare (like the acronym finder) the key order is important.

a few years ago I made an anagram solver that actually stored a serialized version of the count_chars() result in the database, then all I had to do was apply count_chars() to the input word, serialize() it, and look for that in the DB

Wouldn't it have been a lot easier to just sort the letters of your word into alphabetical order and use that as the DB index?

I think the anagram-solver was the result of a solution looking for a problem. I had run across the count_chars() function for some reason or other, and I realized that its results would be the same for any two combinations of the same letters, which led to the idea of an anagram-solver. If I had started out simply with the requirement to create an anagram-solver, who knows?

As to simpler, while your alternative supplies a more compact result that might qualify as "simpler", it's a bit more subjective as to which is simpler to achieve:

Not really a big difference, and once you've indexed it in the DB, probably not any difference in performance (okay, if we're counting micro- or even nanoseconds, a few less bytes to exchange between the app and the DB might matter ), so I certainly have no argument against your proposal, but would be reasonably satisfied with either, I think.