DamienRoche Posted October 14, 2008 Share Posted October 14, 2008 I have this array - $arr[] Say I do this: foreach($arr as $arrtest){ echo "$arrtest index number:()"; } How would I go about getting the index number of $arr? I can just apply a loop because the arr isn't always in the same order. Any ideas?- thanks. Quote Link to comment https://forums.phpfreaks.com/topic/128418-solved-how-to-extract-an-array-index-number/ Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 Use the expanded syntax for foreach foreach($arr as $key => $arrtest){ echo "$arrtest index number:($key)"; } Quote Link to comment https://forums.phpfreaks.com/topic/128418-solved-how-to-extract-an-array-index-number/#findComment-665385 Share on other sites More sharing options...
DamienRoche Posted October 14, 2008 Author Share Posted October 14, 2008 Perfect! -thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/128418-solved-how-to-extract-an-array-index-number/#findComment-665386 Share on other sites More sharing options...
Orio Posted October 14, 2008 Share Posted October 14, 2008 Use the manual, it's the best resource. foreach() Orio. Quote Link to comment https://forums.phpfreaks.com/topic/128418-solved-how-to-extract-an-array-index-number/#findComment-665389 Share on other sites More sharing options...
DamienRoche Posted October 14, 2008 Author Share Posted October 14, 2008 Thanks Orio, I use the manual every day. This seems to be an array thing, the only relation to the foreach is that it has the support for this array technique. I just tested outside a foreach. Thanks for reaffirming the importance any way. Quote Link to comment https://forums.phpfreaks.com/topic/128418-solved-how-to-extract-an-array-index-number/#findComment-665406 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.