I'm writing a script that needs to identify every 7th number where the first number of the sequence is 0 (so the sequence is 6, 13, 20, 27, 34, 41, 48, etc.)
Here's what I've got so far (which works in a limited way), but I'd prefer to write a loop so that the values in the sequence don't have to be hardcoded:
<?php
$x = 7;
if ($x === 6 || $x === 13 || $x === 20 || $x === 27 || $x === 34 || $x === 41 || $x === 48) {
$result = 1;
} else {
$result = 0;
}
echo $result;
?>
Thanks in advance for any advice!
Update: Here's my updated script using @robbieaverill 's solution and checking the values against an array. There are many great solutions here, thanks everyone!
<?php
$divisor = 7;
$limit = 500;
$sequence = array();
for ($i = 0; $i <= $limit; $i++) {
if (is_int(($i + 1) / $divisor)) {
$sequence[] = $i;
}
}
$x = 41;
if (in_array($x, $sequence, true)) {
$result = 1;
} else {
$result = 0;
}
echo $result;
?>
The output here is 1, indicating that if the value of $x is 41 it is found within the $sequence array.