Skip to content

Instantly share code, notes, and snippets.

View aran112000's full-sized avatar

Aran Reeks aran112000

View GitHub Profile
@aran112000
aran112000 / BinarySearchString.php
Last active May 6, 2020 20:57
Example of a simple function to perform a Binary Search in PHP to search for a String value
<?php
/**
* @param string $value The value you're searching for
* @param array $dataSet Your sorted data set to search
*
* @return int Returns the key matched, or -1 if no match is found
*/
function binarySearchString(string $value, array $dataSet): int
{
@aran112000
aran112000 / array_ksearch.php
Last active August 28, 2019 10:02
Search a PHP array for a matching key - array_ksearch(), array_kisearch()
<?php
/**
* Search an array recursively looking for a key containing the supplied $search_string
*
* array_ksearch() is case-sensitive, where as array_kisearch() is case-insensitive
*
* Returns an array containing all matched key(s) and their associated value(s), or an empty array upon no matches
*
* @param array $array