What would be quicker? Looping through a for loop of an array, looking to see if the value of an element matches a string, or looking for the sub string in a larger string?
What I want to do is see if an html tag is an inline tag or not. I want to look at the tag name and then check if it is inline by looking in an array of tag names (that are inline). Would this be quicker if I just made a string of the inline tags and checked this for a substr?
Also is it quicker to loop through an array with numbers as elements, or an assoc. array with strings as element names?
Looking for a string
Moderator: General Moderators
-
filippo.toso
- Forum Commoner
- Posts: 30
- Joined: Thu Aug 07, 2008 7:18 am
- Location: Italy
- Contact:
Re: Looking for a string
From my experience, the best way to achieve what you need is to create an ordered array with the names of the inline tags and then execute a binary search. This will be a lot faster than any other solution.
Re: Looking for a string
How many inline tags can there be?? I doubt that there are so many that it will make any measurable difference. If you had thousands of elements to search, there might be some point in trying to optimize it, but for less than a hundred elements? Probably not.