I have an array that looks like:
Array ( [2.5] => ABDE [4.8] => Some other value )
How would I find any key/value pair where the k
Old question, but here's what I like to do:
$array = [ '2.5' => 'ABDE', '4.8' => 'Some other value' ];
preg_grep + array_keys will find all keys
$keys = preg_grep( '/^2\.\d/i', array_keys( $array ) );
You can add array_intersect_key and array_flip to extract a slice of the array that matches the pattern
$vals = array_intersect_key( $array, array_flip( preg_grep( '/^2\.\d/i', array_keys( $array ) ) ) );