waynew Posted July 14, 2008 Share Posted July 14, 2008 I have an array that has two values. Problem is, I need a way to find out what the index of the last element is. Remember that I can't use sizeof as the index of the first value may be 6. Quote Link to comment https://forums.phpfreaks.com/topic/114649-solved-last-index-of-an-array/ Share on other sites More sharing options...
trq Posted July 14, 2008 Share Posted July 14, 2008 echo end($arr); Quote Link to comment https://forums.phpfreaks.com/topic/114649-solved-last-index-of-an-array/#findComment-589520 Share on other sites More sharing options...
trq Posted July 14, 2008 Share Posted July 14, 2008 Sorry, didn't read your question too well. $keys = array_keys($arr); echo end($keys); Quote Link to comment https://forums.phpfreaks.com/topic/114649-solved-last-index-of-an-array/#findComment-589521 Share on other sites More sharing options...
waynew Posted July 14, 2008 Author Share Posted July 14, 2008 Okay, maybe that's not the right logic. I have an array of values with, as I said, indexes that may start at any given number. How can I assign that array onto another array in a way that the new array will begin at 0? Quote Link to comment https://forums.phpfreaks.com/topic/114649-solved-last-index-of-an-array/#findComment-589523 Share on other sites More sharing options...
samshel Posted July 14, 2008 Share Posted July 14, 2008 do you want to retain the old indexes ? $arr = array(6=>"one", 5=>"two", 0=>"three", 2=>"four"); $arrOne = array(0=>"three", 2=>"four", 5=>"two", 6=>"one"); $arrTwo = array(0=>"one", 1=>"two", 2=>"three", 3=>"four"); do you want $arrOne or $arrTwo ? Quote Link to comment https://forums.phpfreaks.com/topic/114649-solved-last-index-of-an-array/#findComment-589575 Share on other sites More sharing options...
waynew Posted July 14, 2008 Author Share Posted July 14, 2008 Sorry. Thanks for the help. I've already solved this part and forgot to press topic solved. Quote Link to comment https://forums.phpfreaks.com/topic/114649-solved-last-index-of-an-array/#findComment-589579 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.