Struggling with a tiny problem.
I have an array:
Array
(
[0] =>
[6] => 6
[3] => 5
[2] => 7
)
I am checking if a set value is in the array.
if(in_array(5, $array)) {
//do something
} else {
// do something else
}
The thing is, when it find the value 5 in array, I really need the key to work with in my “do something”.
In this case I need to set:
$key = 3;
(key from the found value in_array).
Any suggestions?
array_search()is what you are looking for.