On 31 August 2010 17:06, Tontonq Tontonq <root...@gmail.com> wrote:
> Array
> (
> [300] => 300
> [301] => 301
> [302] => 302
> [303] => 303
> [304] => 304
> [305] => 305
> [306] => 306
> [307] => 307
> [308] => 308
> [309] => 309
> [310] => 310
> [311] => 311
> [312] => 312
> [313] => 313
> [314] => 314
> [165] => 165
> [166] => 166
> [167] => 167
> [168] => 168
> [169] => 169
> [170] => 170
> [171] => 171
> [172] => 172
> [173] => 173
> [201] => 201
> [202] => 202
> [203] => 203
> [204] => 204
> [205] => 205
> [206] => 206
> [207] => 207
> [208] => 208
> [209] => 209
> [210] => 210
> [211] => 211
> [212] => 212
> [213] => 213
> [214] => 214
> [215] => 215
> [315] => 315

$newData = array();
$firstValue = null;
$lastValue = null;
foreach($data as $value)
        {
        // New first value.
        if (is_null($firstValue))
                {
                $firstValue = $value;
                $lastValue = null;
                }

        // New last value and is the same or 1 more.
        if (is_null($lastValue))
                {
                $lastValue = $value;
                }

        // Is the value this or the next value from $lastValue
        else if($value == $lastValue || $value == 1 + $lastValue)
                {
                $lastValue = $value;
                }

        // We have a break;
        else
                {
                $newData[] = "$firstValue-$lastValue";
                $firstValue = $lastValue = null;
                }
        }




-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to