I am using an array with titles. Each titles index corresponds to an id in a database which contains html for that given title.
Lets say I have a string which contains one of the titles.
title = "why-birds-fly";
titles[] // an array which contains all the titles
To use the string "title" to get the corresponding id I could do:
for (i = 0; i < titles.length-1; i++) {
if (titles[i] == title)
return i+1;
}
Another method I could use is to create an associative array together with the titles array which is the exact opposite of titles. That is, it uses the string as an index and returns the number.
titles_id {blah:0,why-birds-fly:1,blah2:2}
I could then access the ID by:
return titles_id[title]+1;
What would be most effective considering CPU, Memory, etc?
Also, please let me know if my logic is all wrong.
Thanks Willem