in reply to How do I find the array element directly preceeding a 'match'?

for ($i = 0; $i < @array; $i++) { if (matches($array[$i])) { $found = $array[$i-1]; } }
Ugh. What if $i = 0 at the match? You've just indexed into the end of the array? Either start at 1, or redefine your problem for the unusual case.

Originally posted as a Categorized Answer.