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

  • برمجة بي اتش بي

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.

الأجوبة

<?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)
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...