dlebowski Posted May 3, 2010 Share Posted May 3, 2010 I am trying to figure out a way to have php give me the next "available" value, in a list. This seems easy enough, but there may be some values that have a letter in them. So for example, if I have this: 1 2 3 3a 5 5a 7 The next available value would be 4. If I have this: 1 2 3 3a 4 5 5a 7 The next available value would be 6. I am using this code to sort list correctly, and it appears to be working fine: $sql="select LotNumber FROM lots WHERE Date='$Date' ORDER BY CAST(LotNumber AS UNSIGNED) asc, LotNumber"; I just need to now be able to take that list, and display the next available numeric value. Any help on this would be greatly appreciated. Thank you in advance! Ryan Link to comment https://forums.phpfreaks.com/topic/200515-display-missing-value-in-list-code/ Share on other sites More sharing options...
anups Posted May 3, 2010 Share Posted May 3, 2010 //assume you have array as $arr = array('1','2','3','3a','5','5a','6','7'); function toInt($n){ return (int)$n; } $newArr = $arr; array_walk($newArr,"toInt"); print_r($newArr); $temp =1; for($i=0;$i<count($newArr)+1;$i++) { if(!in_array($temp,$newArr)){ echo "Aval:- ".$temp; exit; } ++$temp; } Link to comment https://forums.phpfreaks.com/topic/200515-display-missing-value-in-list-code/#findComment-1052211 Share on other sites More sharing options...
dlebowski Posted July 20, 2010 Author Share Posted July 20, 2010 Thank you. That was it! Link to comment https://forums.phpfreaks.com/topic/200515-display-missing-value-in-list-code/#findComment-1088719 Share on other sites More sharing options...
dlebowski Posted July 20, 2010 Author Share Posted July 20, 2010 I want to open this back up again because I have one more issue. If I have 1, 2, 3, 3a, 3b, 3c and I want the next value after 3, which can't be 3a/3b/3c because they are already used, how would I do that? Basically, if I want next value "available" after 3, I would want 3d. Can this be done? Let me know if I need to explain it a little better. Thank you! Link to comment https://forums.phpfreaks.com/topic/200515-display-missing-value-in-list-code/#findComment-1088792 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.