luvz2drv Posted September 25, 2007 Share Posted September 25, 2007 this is what I have an array of numbers 1,2,3,4,5,11,17,18,19,24 what I need to do is have it print 1-5,11,17-19,24 can any one please help me get this snipet of code constructed thanks Jonathon is the only thing I found close but it is not for php... use Set::IntSpan; use strict; sub consecutive_integers_list { my(@integers) =sort { $a <=> $b } @{+shift}; my $set = Set::IntSpan->new(join ",", @integers); $set->run_list; } my @integers = qw( 20 2 3 4 5 6 7 23 19 17 25 30 11 12 22 21 68 103829 + 24 18 ); print consecutive_integers_list(\@integers); //prints: 2-7,11-12,17-25,30,68,103829 Link to comment https://forums.phpfreaks.com/topic/70608-php-function-to-groupsort-numbers/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.