Looking for a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RiscOS
Forum Newbie
Posts: 4
Joined: Fri Aug 08, 2008 6:08 am

Looking for a string

Post by RiscOS »

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?
filippo.toso
Forum Commoner
Posts: 30
Joined: Thu Aug 07, 2008 7:18 am
Location: Italy
Contact:

Re: Looking for a string

Post by filippo.toso »

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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Looking for a string

Post by califdon »

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.
Post Reply