1,2,3,4,8 ===> 1-4, 8 How do I do this in php?

I’m trying to figure out:
1,2,3,4,8 ===> 1-4, 8

		$t=explode("+", $verse0[$i]);
		print_r($t);
		/*
		$s = '';
		$c = count($t);
		for($i=0; $i<$c; $i++) {
			$start = $t[$i];
			$end = '';
			if($i+2 < $c && $start+1 == $t[$i+1] && $start+2 == $t[$i+2]) {
				$i+=2;
				$end = $t[$i];
				while(++$i < $c) {    
					if($end+1 == $t[$i]) $end = $t[$i];
					else break;
				}
			}
			$s .= $end ? $start.'-'.$end.', ' : $start.', ';
		}
		*/
		echo $verse0[$i];
		//echo $s;

If you cannot be bothered to construct a question, how do you expect others to be bothered to construct an answer? :wink:


March called, it wants its question* back.

[size=1]* See your previous thread on precisely this topic: http://www.sitepoint.com/forums/showthread.php?t=665995[/size]

Was there a problem with the solutions that were proposed that wasn’t addressed?

I have an array of numbers. Some may be incremental like 1+2+3+4 and some at random like 5+9+17

Is there a function(s) which will recognize the patterns?

Oh yeah. Thanks. It shows you I haven’t solved it yet.