Q:

Write a PHP program to check a given array of integers of length 1 or more and return true if 10 appears as either first or last element in the given array

0

Write a PHP program to check a given array of integers of length 1 or more and return true if 10 appears as either first or last element in the given array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($nums)
 { 
    return $nums[0] == 10 || $nums[sizeof($nums) - 1] == 10;
    
 }   

var_dump(test([10, 20, 40, 50]));
var_dump(test([5, 20, 40, 10]));
var_dump(test([10, 20, 40, 10]));
var_dump(test([12, 24, 35, 55]));

Sample Output:

bool(true)
bool(true)
bool(true)
bool(false)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now