Q:

Write a PHP program to check a given array of integers of length 1 or more and return true if the first element and the last element are equal 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 the first element and the last element are equal 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 sizeof($nums) > 0 && $nums[0] == $nums[sizeof($nums) - 1];
    
 }   

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

Sample Output:

bool(false)
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