SchweppesAle Posted June 25, 2009 Share Posted June 25, 2009 hi, I wanted to know if there's a method which returns the highest element number in an array rather than the highest value ex: max() Thanks Link to comment https://forums.phpfreaks.com/topic/163679-highest-element-in-an-array/ Share on other sites More sharing options...
SchweppesAle Posted June 25, 2009 Author Share Posted June 25, 2009 something which collapses all "NULL" elements within an array would work too. EX: array1: [0] = 10 [1] = NULL [2] = NULL [3] = NULL [4] = 5 [5] = 8 somemethod(array1) newarray: [0] = 10 [1] = 5 [2] = 8 Link to comment https://forums.phpfreaks.com/topic/163679-highest-element-in-an-array/#findComment-863616 Share on other sites More sharing options...
phant0m Posted June 25, 2009 Share Posted June 25, 2009 http://ch.php.net/end as for your 2nd question: $temp = array(); foreach($array as $element){ if($element !== NULL){ $temp[] = $element; } } $array = $temp; //edit: to get the highest index, why not use count($array)-1; //(provided the index is continuous) else: use array_keys() with end() Link to comment https://forums.phpfreaks.com/topic/163679-highest-element-in-an-array/#findComment-863619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.