thiggins09 Posted July 27, 2007 Share Posted July 27, 2007 Hi, I have an array and each key in it is labled a user's ID. I was wondering what the most efficient way to get the real place of that key would be. For example: $arr[342]=34; $arr[235]=55; $arr[164]=64; $arr[766]=4; key 342 is first in the array, 235 second an so on. So if I wanted to tell that 744 is really fourth in the array, what would be the best way? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 27, 2007 Share Posted July 27, 2007 you can use foreach is that? Quote Link to comment Share on other sites More sharing options...
thiggins09 Posted July 27, 2007 Author Share Posted July 27, 2007 I know that would do it but I was hoping there was a faster way. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted July 27, 2007 Share Posted July 27, 2007 There isn't a specific function to find what you want, you'll have to loop through the array... <?php $arr[342]=34; $arr[235]=55; $arr[164]=64; $arr[766]=4; $key_to_find = 164; $cnt = 1; while ($values = each($arr)) { if ($values['key'] == $key_to_find) { $place = $cnt; break; } $cnt++; } echo $place; ?> 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.