Write a PHP program to check a given array (length will be atleast 2) of integers and return true if there are two values 15, 15 next to each other.
<?php function test($numbers) { for ($i = 0; $i < sizeof($numbers) - 1; $i++) { if ($numbers[$i + 1] == $numbers[$i] && $numbers[$i] == 15) return true; } return false;; } var_dump(test([5, 5, 1, 15, 15])); var_dump(test([15, 2, 3, 4, 15])); var_dump(test([3, 3, 15, 15, 5, 5])); var_dump(test([1, 5, 15, 7, 8, 15]));
Sample Output:
bool(true) bool(false) bool(true) bool(false)
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