PHP Fastest search algorithm for two dimensional array -


i working on data import process , need search different 2 dimensional arrays specific code. array structure this:

index id   code ---------------- 0     34    p1 1     5     ar 2     71    y2 3     677   ui 4     14    io ...  

in import file have code id dataset array (above). need know best algorithm id through code fast. doing ids:

foreach ($dataset $row) {    if ($row['code'] == $code) {        return $row['id'];    } } 

note: dataset arrays sorted in ascending order code when fetched database.

the binary search algorithm might have worked if code integer. in current scenario alpha-numeric, have search algorithm.

in view, instead of searching in array better search while fetching db.

"select * table_name `code` = '".$code."'" 

because if table has many records fetch required one.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -