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. 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); 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); 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? 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 ? 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. 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
Archived
This topic is now archived and is closed to further replies.