[ACCEPTED]-how to match value in PHP array and then find key value?-variables
Accepted answer
Use array_search()
.
$key = array_search($color, $colorArray);
To ensure you got a match, make 1 sure you compare it to FALSE
and not just falsy.
if ($key !== FALSE) {
// Match made.
}
Use array_search, here's an example:
$key = array_search($color, $colorArray);
In your example, this 1 would return 0.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.