php array get positions of the specific value

arrays, php, position

Solution

Use array_keys with the optional search parameter, that should return all of the keys.

`$matches = array_keys($my_array, 5);`

Problem

I have one array and I want to get the positions of one specific value Example: ``` $my_array = array(0,2,5,3,7,4,5,2,1,6,9); ``` My search is Number 5 the positions of Number 5 in array was (2 and 6) If i call the `array_search` function, always returns the first position in array witch is 2. Is there anyway to get the two ore more positions of specific value?

Original source