If you have a value and want to find the key, use array_search()
like this:
$arr = array ('first' => 'a', 'second' => 'b', );
$key = array_search ('a', $arr);
$key
will now contain the key for value 'a'
(that is, 'first'
).
More Related Contents:
- array_key_exists is not working
- how can i passed array into a function in php [closed]
- Needle in a Haystack for Php [closed]
- Multiple inputs with same name through POST in php
- Creating one array from another array in php [closed]
- Filter array by its keys using an array of allowed keys
- Count number of values in array with a given value
- PHP Foreach Pass by Reference: Last Element Duplicating? (Bug?) [duplicate]
- Which is faster in PHP, $array[] = $value or array_push($array, $value)?
- Difference between method calls $model->relation(); and $model->relation;
- array_unique for objects?
- A formula to find prime numbers in a loop
- String with array structure to Array [duplicate]
- in_array multiple values
- php array behaving strangely with key value 07 & 08
- Difference between array_map, array_walk and array_filter
- Checking if array is multidimensional or not?
- PHP how to retrieve array values
- How can I use in_array if the needle is an array?
- Add a prefix to each item of a PHP array
- How to get the last element of an array without deleting it?
- Group 2d array data using column value to create a 3d array
- Split array into a specific number of chunks
- While destructuring an array, can the same element value be accessed more than once?
- Concatenate values of n arrays in php
- How to convert array to a string using methods other than JSON?
- How to insert json array into mysql database
- Why do I get “Resource id #4” when I apply print_r() to an array in PHP? [duplicate]
- How to set an option from multiple options or array with different values to views as selected in select box using PHP
- PHP Spread Syntax in Array Declaration