What search algorithm does in_array() use?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Does in_array() use a search algorithm (i.e., binary search), or does it
check sequentially each element in the array?

I am using in_array() within a while{} loop to check query results against
an access-list array to produce a third array containing items that
successfully passed the comparison test.  Because the two starting arrays in
the worst-case scenario can have 8,000 items each, the loop is timing out.
Advice or alternative methods are appreciated.

Code Sample:
<?php
function check_results($results, $access_list)
{ # Check for $results in array $access_list and
  # add matches to array $match.

  $result = false;
  $match = array();

  while ($r = mysql_fetch_row($results))
  { if ( in_array($r[0], $access_list) )
    { $match[] = $r; }
  }

  if ( count($match) > 0 ) { $result = $match; }

  return $result;
}
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux