PHP code example of ezzaze / binary-search

1. Go to this page and download the library: Download ezzaze/binary-search library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ezzaze / binary-search example snippets


use Ezzaze\BinarySearch\BinarySearch;

$haystack = range(1,1000000);
$result1 = BinarySearch::exists(500, $haystack); //true
$result2 = BinarySearch::exists(0, $haystack); //false

use Ezzaze\BinarySearch\BinarySearch;

$haystack = range(1,1000000);
$result = BinarySearch::exists(500, $haystack, false);

use Ezzaze\BinarySearch\BinarySearch;

$haystack = array_chunk(range(1,1000000), 2);
$result1 = BinarySearch::exists([500,501], $haystack); //true
$result2 = BinarySearch::exists([501, 502], $haystack); //false