in reply to How do I find the array element directly preceeding a 'match'?
If you want to insist doing it in foreach style:for ($i = 0; $i < @array; $i++) { if (matches($array[$i])) { $found = $array[$i-1]; } }
foreach $item (@array) { if (matches($item)) { $found = $last; } $last = $item; }
Originally posted as a Categorized Answer.
|
|---|