Assuming I had this result of `print_r` below `Array ( [0] => 10 [1] => 11 )` which is the result of months within a specific year *october* and *november*. I wonder how to return true if the array return in correctly order months until December example => `Array ( [0] => 8 [1] => 9 [2] => 10 [3] => 11 [4] => 12)` . and return false if array not in orderly months for example => `Array ( [0] => 2 [1] => 3 [2] => 10 [3] => 12` <-- months is skipping.

```
$sql4 = "SELECT monthClose 
         FROM tblAccAccountClosing
         WHERE yearClose = '".$yearClose."' 
         AND settingType = 'month'
         AND STATUS = 'open' ";
$GetResult4 = $pdo->FetchData($sql4, $pdo->DEFAULT_PDO_CONNECTIONS);
while ($row4 = $GetResult4->fetch()){       
    $monthsArray[] = $row4['monthClose'];   
}

print_r ($monthsArray);

```

* There is no min on month, it could be start from any months.
* There is no duplicate data will return.
* Some example here.

```js
Array ( [0] => 9 [1] => 10 [2] => 11 ) --> return false (because result not until 12)
Array ( [0] => 1 [1] => 2 [2] => 10 [3] => 12 ) --> return false
Array ( [0] => 3 [1] => 4 [2] => 5 [3] => 6 )  --> return false
Array ( [0] => 1 [1] => 12 )  --> return false

Array ( [0] => 7 [1] => 8 [2] => 9 [3] => 10 [4] => 11 [5] => 12) --> return true
Array ( [0] => 11 [1] => 12 ) --> return true
Array ( [0] => 12 ) --> return true
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12) --> return true
```

Appreciate your help.
['https://Stackoverflow.com/questions/65119282', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11393883/']
A little hesitant to post an answer because the requirements for determining validity are vague but from your comments these are invalid:

* 3,4,6 (missing 5)
* 3,4,4,5 (duplicate 4)
* 0,1 (0 is invalid)
* 10,11,12,13 (13 is invalid)
* 9,10,11 (invalid because 12 is missing)

<http://sandbox.onlinephpfunctions.com/code/8967ae95c5751a8a75a1187d0470b6f527278453>

```
<?php

function areMonthsValid(array $input)
{   
    // Input is invalid if it contains < 1 or > 12
    if (min($input) < 1 || max($input) > 12) {
        return false;
    }

    // This is used as the source to compare against and we assume it is right. 
    // It will have a range of numbers starting from the min to 12.
    $template = range(min($input), 12);

    // Now, compare the 2 arrays and see if there are any differences. 
    // If there are differences you know that $input has a different list than $template.
    // The order of these arrays matters.
    // Empty = no differences
    return empty(array_diff($template, $input));

    // Using `array_diff` will not fail on [10,10,11,12]
    // If you want that to fail, you can count the array values.
    // return count($template) === count($input);
}

var_dump(areMonthsValid([3,10]));        // false
var_dump(areMonthsValid([3,4,5,6]));     // false
var_dump(areMonthsValid([3,10]));        // false
var_dump(areMonthsValid([3,5,6]));       // false
var_dump(areMonthsValid([3,5,5,6]));     // false
var_dump(areMonthsValid([-2,-1,0,1]));   // false
var_dump(areMonthsValid([10,11,12,13])); // false
var_dump(areMonthsValid([10,11,12]));    // true

```
Maybe you can try this solution

```
function isValidSequence(array $sequence) {
for($i=0; $i < count($sequence) - 1; ++$i) {

    if ($sequence[$i+1] !== ($sequence[$i] + 1)) {
        //if not in sequence
        return false;
    }
}
//return true if on sequence or only one element
return true;
}

```