acidglitter Posted May 18, 2008 Share Posted May 18, 2008 say you have an array like this key[0] => value(blue) key[1] => value(green) key[2] => value(red) if you put like $array[1] it will return "green" but is there a way you can do it the other way around? like $array['green'] and it will return "1"? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 18, 2008 Share Posted May 18, 2008 $newarray = array_combine(array_values($array), array_keys($array)); echo $newarray['green']; //Outputs: 1 Quote Link to comment Share on other sites More sharing options...
trq Posted May 18, 2008 Share Posted May 18, 2008 One way would be to use array_flip to flip the array around. Quote Link to comment Share on other sites More sharing options...
sasa Posted May 18, 2008 Share Posted May 18, 2008 array_search() function Quote Link to comment Share on other sites More sharing options...
acidglitter Posted May 18, 2008 Author Share Posted May 18, 2008 thanks for all of the replies! that fixed my problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.