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"? Link to comment https://forums.phpfreaks.com/topic/106177-solved-arrays-but-backwards/ 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 Link to comment https://forums.phpfreaks.com/topic/106177-solved-arrays-but-backwards/#findComment-544241 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. Link to comment https://forums.phpfreaks.com/topic/106177-solved-arrays-but-backwards/#findComment-544242 Share on other sites More sharing options...
sasa Posted May 18, 2008 Share Posted May 18, 2008 array_search() function Link to comment https://forums.phpfreaks.com/topic/106177-solved-arrays-but-backwards/#findComment-544248 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 Link to comment https://forums.phpfreaks.com/topic/106177-solved-arrays-but-backwards/#findComment-544249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.