"how to find the best matching key in a php array" Code Answer

1

a simple, but brute force method:

$distance = 1000000;  // initialize distance as "far away"
foreach ($array as $idx => $value)
   if (abs ($idx - $target_index) < $distance)
   {
      $distance = abs ($idx - $target_index);
      $best_idx = $idx;
   }
By Alex Nikitin on July 16 2022

Answers related to “how to find the best matching key in a php array”

Only authorized users can answer the Search term. Please sign in first, or register a free account.