What is the fastest/best way to create a function that retrieves a list of keys, that all contains a specific value in an array:
$array = ( 0 => 0,
1 => 0,
2 => 1,
3 => 2,
4 => 1 );
$keys= retrieve_keys_with_value( 1, $array );
var_dump($keys);
/*
array(2) {
[0] => int(2)
[1] => int(4)
}
*/
http://www.php.net/manual/en/function.array-keys.php
You may also want to pass the third parameter (strict checking). Default is
false.Remember. It’s PHP there is almost always a function for what you are doing 😉