Write a PHP program to check a given array of integers and return true if the array contains three increasing adjacent numbers.
<?php function test($numbers) { for ($i = 0; $i <= sizeof($numbers) - 3; $i++) { if ($numbers[$i] == $numbers[$i + 1] - 1 && $numbers[$i] == $numbers[$i + 2] - 2) { return true; } } return false; } var_dump(test([1, 2, 3, 5, 3, 7])); var_dump(test([3, 7, 5, 5, 3, 7])); var_dump(test([3, 7, 5, 5, 6, 7, 5]));
Sample Output:
bool(true) bool(false) bool(true)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer