|
Posted by Thomas Mlynarczyk on 11/18/07 13:49
Also sprach Csaba Gabor:
> function longestMatchingKey ($aSrch, $aSubj) {
> if (array_key_exists($k=implode(".", $aSrch), $aSubj)) return $k;
> for ($i=sizeof($aSrch);$k=substr($k,0,-strlen($aSrch[--$i])-1);)
> if (array_key_exists($k, $aSubj)) break;
> return $k; }
> (5 lines total, one loop, no reversing, watch for wrapping) Though
> perhaps not overly different from what you suggested...
Maybe not overly different, but certainly much more efficient and elegant!
Thanks a lot! :-)
Greetings,
Thomas
--
C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
[Back to original message]
|