Write a PHP program to create a new array length 3 from a given array (length atleast 3) using the elements from the middle of the array

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

Write a PHP program to create a new array length 3 from a given array (length atleast 3) using the elements from the middle of the array

الأجوبة

<?php
function test($numbers)
 { 

   return [$numbers[sizeof($numbers) / 2 - 1], $numbers[sizeof($numbers) / 2], $numbers[sizeof($numbers) / 2 + 1]];
 }   

$result = test([1, 5, 7, 9, 11, 13] );
echo "New array: " . implode(',', $result);

Sample Output:

New array: 7,9,11
هل كان المحتوى مفيد؟

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

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