purencool Posted August 17, 2009 Share Posted August 17, 2009 Hi people, If I have an array that is something like what is below. How do I get a copy of the key number into a variable. I just want the number nothing else? $chickens[0]=> 12 $chickens[1]=> 1 Link to comment https://forums.phpfreaks.com/topic/170719-solved-copy-key-value-in-an-array/ Share on other sites More sharing options...
GingerRobot Posted August 17, 2009 Share Posted August 17, 2009 What do you mean? Do you want to return the key of the array for a corresponding value? You can do this with array_search Link to comment https://forums.phpfreaks.com/topic/170719-solved-copy-key-value-in-an-array/#findComment-900398 Share on other sites More sharing options...
oni-kun Posted August 17, 2009 Share Posted August 17, 2009 It should be like this, if you use the above suggestion. $chickens[0]=> 12 $chickens[1]=> 1 $key = array_search('12', $chickens); // $key = 0; $key = array_search('1', $chickens); // $key = 1; Link to comment https://forums.phpfreaks.com/topic/170719-solved-copy-key-value-in-an-array/#findComment-900402 Share on other sites More sharing options...
purencool Posted August 17, 2009 Author Share Posted August 17, 2009 thanks that is what I am looking for Link to comment https://forums.phpfreaks.com/topic/170719-solved-copy-key-value-in-an-array/#findComment-900408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.