3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function bin_search( $search, $array, $low=0, $high=null, $search = 0 ) { if( $search == count( $array ) ) return null; if( ! is_array( $array ) || empty( $array ) ) return null; if( empty( $high ) ) $high = count( $array ) - 1; // not found if( $low === $high) return null; $mid = floor( ( $high - $low ) / 2 ); $key = ( $high - $mid ) - 1; // found! if( $array[ $key ] === $search ) return $key; if( $search < $array[ $key ] ) { return bin_search( $search, $array, $low, $key, ++$search ); } else { return bin_search( $search, $array, $key, $high, ++$search ); } } $array = range(1,5); $key = bin_search( 3, $array ); echo "Key=" . $key; echo "Value=" . $array[ $key ];
based on ZTEgN
Output for 7.0.0 - 7.0.1
Fatal error: Redefinition of parameter $search in /in/SlG11 on line 3
Process exited with code 255.
Output for 5.3.21 - 5.6.28
Key=0Value=1