Write a PHP program to check if one of the first 4 elements in an array of integers is equal to a given element
<?php function test($nums, $n) { return sizeof($nums) < 4 ? in_array($n, $nums) : in_array($n, array_slice($nums, 0, 4)); } var_dump(test(array(1,2,9,3), 3)); var_dump(test(array(1,2,3,4,5,6), 2)); var_dump(test(array(1,2,2,3), 9));
Sample Output:
bool(true) 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