This is only a concept to be analyzed
is_sequence - Verify if number range have correct sequence or arithmetic progression
bool is_sequence ( array $array , int|float $sequence [, int $flags ] )
array
array with numbers to validation
sequence
sequence number to validation
flags
set if number sequence is positive or negative
Avaliable flags
Flag | Description |
---|---|
SEQUENCE_POSITIVE | Define sequence as positive |
SEQUENCE_NEGATIVE | Define sequence as negative |
This function return TRUE if array sequence is correct, FALSE otherwise.
Example #1 is_sequence() examples
<?php
$array = array(5, 7, 9, 11, 13);
$sequence = 2;
if (is_sequence($array, $sequence) === true) {
echo "Yes, ".implode(", ", $array)." have correct sequence of ".$sequence." number";
} else {
echo "No, ".implode(", ", $array)." don't have sequence of ".$sequence." number";
}
?>
Example #2 is_sequence() examples
<?php
$array = array(1.4, 1.2, 0.9, 0.7, 0.5);
$sequence = 0.2;
var_dump(is_sequence($array, $sequence, SEQUENCE_NEGATIVE));
?>
The above example will output:
bool(false)