如需求:最高延续打卡若干天? 或者一串数字,最大延续数字有若干个。

$nums = ['2018-10-09','2018-10-10','2018-10-11','2018-10-13','2018-10-15','2018-10-16','2018-10-17','2018-10-18'];
    $max  = 0;
    $hash = [];
    foreach ($nums as $val) {
        $hash[$val] = 1;
    }
    foreach ($nums as $val){
        $num = 1;
        if (!$hash[$val - 1]) {
            while($hash[++$val]) $num++;
        }
        $max = $num > $max ? $num : $max;
    } 

    echo $max;
$nums = [0, 3, 7, 2, 5, 8, 4, 6, 0, 1];
    $max  = 0;
    $hash = [];
    foreach ($nums as $val) {
        $hash[$val] = 1;
    }
    foreach ($nums as $val){
        $num = 1;
        if (!$hash[$val - 1]) {
            while($hash[++$val]) $num++;
        }
        $max = $num > $max ? $num : $max;
    } 

    echo $max;