Skip to content

array_binary_search

Hyomoto edited this page Jun 13, 2021 · 2 revisions
Jump To Go Back Arguments

array_binary_search( array, value, *func )

Returns: [mixed or ValueNotFound](mixed or ValueNotFound)

Throws: InvalidArgumentType

Uses a binary search on the given array to find the position of value. The array must be sorted for binary search to work, otherwise results will be inconsistent. You can override the function used for comparison by specifying func. If the value is not found, ValueNotFound will be returned. If an array is not provided to search, or a method is not provided for func InvalidArgumentType will be thrown.

array_binary_search( [ 10, 20, 30, 40, 50 ], 40 );
Output: 3

Arguments

Name Type Purpose
array [Array](array) The array to search
value [Mixed](mixed) The value to find
*func method optional: If provided, will be used for sake of comparison
Clone this wiki locally