i have this array
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
how can i get an element's key?(for example a=0,c=2)
i have this array
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)
how can i get an element's key?(for example a=0,c=2)
http://www.php.net/manual/en/function.array-flip.php
Using array_search http://php.net/manual/en/function.array-search.php
If you just want the keys use array_keys.
If you want to flip the array like you show in your example, use array_flip
Use array_search()
array_keys
:If you want to search, see array_search (http://www.php.net/manual/en/function.array-search.php)
If you are iterating over it, you can use various syntax:
I personally like @SilentGhost's solution but you would suffer a speed penalty if you are doing more than one search, at which point you would want the following: