[UPHPU] better way to find position in an array of numeric values?

Justin Hileman justin at justinhileman.info
Sat May 2 10:59:59 MDT 2009


Wade Preston Shearer wrote:
> On 2 May 2009, at 10:02, Justin Hileman wrote:
>
>> In that case, is count($things) smaller, bigger, or enormously bigger
>> than the max value of $thing['id'] ? I've got an ugly answer, but the
>> efficiency of said ugly answer depends on how many $things you have :)
>
> The max ID will be substantially larger (5-6 digit number) than the
> number nodes in the array (5-20).

My ugly answer would definitely be a bad idea in that case.

In that case, it sounds like your best bet is to make an else clause to 
break out of your loop.

If you only have a handful of $positions and they don't change very 
often, you might consider unrolling the whole process into an if / 
elseif / else mess, as that would be faster than iterating over the array.

-- 
justin
http://justinhileman.com



More information about the UPHPU mailing list