faisalrehmanid/fr-binary-search

此库提供了二维数组的二分查找实现

1.0.0 2021-07-07 05:16 UTC

This package is auto-updated.

Last update: 2024-09-07 12:04:10 UTC


README

此库提供了二维数组的二分查找实现

如何使用?

// What value to search e.g. '2'
$needle = '2';

// Search from array
$haystack = [
    ['id' => '1', 'name' => 'name_1'],
    ['id' => '2', 'name' => 'name_2'],
    ['id' => '3', 'name' => 'name_3']
];

// Search key from array. e.g. 'id' must be ASC sorted
$key = 'id';

// $results always will be array
$results = \FR\BinarySearch\BinarySearchUtil::binarySearch($needle, $haystack, $key);

echo '<pre>';
    print_r($results);
echo '</pre>';

如何测试?

执行PHPUnit测试

  1. 指向 /vendor/bin 目录 cd ./vendor/bin
  2. 执行PHPUnit测试:phpunit --configuration ./../../tests/phpunit.xml
  3. 检查phpunit版本:phpunit --version