Re: array_search function bugged? update

From: Date: Mon, 27 Mar 2006 10:47:41 +0000
Subject: Re: array_search function bugged? update
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-232601@lists.php.net to get a copy of this message
On 27/03/06, je killen <jekillen@prodigy.net> wrote: > Hi all > Here is an update on my problem reported with the array_search function. > to those who directed me to the bug report page, thanks. > There are a number of reports specific to this function. Maybe event > someone else has written a fix. > here is my solution to my problem. There are no open bug reports for array_search(). Loads of bogus ones though. array_search() also completely the wrong tool for the job - the code you posted is much more complicated and slower than it needs to be. That whole palaver that you go through to produce $reduced could be replaced with: $reduced = array_merge(array(), array_unique($str)); That nested loop you use to produce $final would be rather simpler and faster if you just flipped $reduced and used a hash lookup. $charmap = array_flip($reduced); foreach ($str as $char) { $final[] = $charmap[$char]; } -robin

« previous php.general (#232601) next »