faisalrehmanid / fr-binary-search
此库提供了二维数组的二分查找实现
1.0.0
2021-07-07 05:16 UTC
Requires
- php: >=5.4.0
Requires (Dev)
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测试
- 指向 /vendor/bin 目录
cd ./vendor/bin
- 执行PHPUnit测试:
phpunit --configuration ./../../tests/phpunit.xml
- 检查phpunit版本:
phpunit --version