[ACCEPTED]-how to match value in PHP array and then find key value?-variables

Accepted answer
Score: 14

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.
}
Score: 1

You're looking for array_search: http://www.php.net/array_search

0

Score: 1

Use array_search, here's an example:

$key = array_search($color, $colorArray);

In your example, this 1 would return 0.

More Related questions