You could use array_search()
to find the first matching key.
From the manual:
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array); // $key = 1;
More Related Contents:
- Getting all possible combination of an array
- PHP – File to Associative Array with 1 key and two values attached
- Json array to json php
- How can I loop through two arrays at once? [duplicate]
- PHP: How to remove specific element from an array?
- Is there a way to find out how “deep” a PHP array is?
- Passing an Array as Arguments, not an Array, in PHP
- PHP append one array to another (not array_push or +)
- PHP: Check if an array contains all array values from another array
- php implode (101) with quotes
- Combinations, Dispositions and Permutations in PHP
- PHP Add element to every sub array of multi dimension array
- PHP foreach with Nested Array?
- Compare multidimensional arrays in PHP
- PDO fetchAll array to one dimensional
- PHP: Create an array for a range
- Interleaving multiple arrays into a single array
- Generate URL with parameters from an array
- How to cast variable to array
- PHP array, Are array indexes case sensitive?
- Most efficient way to search for object in an array by a specific property’s value
- Treat an array as circular array when selecting elements – PHP [duplicate]
- PHP Array_Sum on multi dimensional array
- Count and display occurrences of unique values in an array
- Is there a way to change all keys in a flat indexed array to the same string (“Name”)? [closed]
- Search and replace multiple values with multiple/different values in PHP?
- Split a string with two delimiters into two arrays (explode twice)
- PHP re-order array of month names
- MySQL PHP – SELECT WHERE id = array()? [duplicate]
- PHP-Sort array based on another array?