I have an array that looks like this:
Array ( [2.5] => ABDE [4.8] => Some other value )
How do I find a key / value pair where the key matches the pattern? I will know the meaning of the first digit in the key, but not the second. therefore, for example, using the prefix "2.", I want to somehow find the key "2.5" and return both the key and the value "ABDE".
I was thinking about using a regex with a pattern like:
$prefix = 2; $pattern = '/'.$prefix.'\.\d/i';
and then loop through the array and validate each key. (by the way, for demonstration purposes only, the $ prefix was hardcoded to 2, but in the real system this value is provided by the user).
I am wondering if there is an easier way to do this?
Thanks.
dot source share