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.for ($i = 0; $i < @array; $i++) { if (matches($array[$i])) { $found = $array[$i-1]; } }
Originally posted as a Categorized Answer.
In reply to Re: How do I find the array element directly preceeding a
by merlyn
in thread How do I find the array element directly preceeding a 'match'?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |