Write a PHP program to create a new array containing the middle elements from the two given arrays of integers, each length 5

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

Write a PHP program to create a new array containing the middle elements from the two given arrays of integers, each length 5

الأجوبة

<?php
function test($nums1, $nums2)
 { 
            return [$nums1[2], $nums2[2]];
    
 }   

$nums1 = [10, 20, -30, -40, 30];
$nums2 = [10, 20, 30, 40, 30];
echo "Original array1: " . implode(',', $nums1) . "\n";
echo "Original array2: " . implode(',', $nums1) . "\n";

$result = test($nums1, $nums2);

echo "New array: " . implode(',', $result);

Sample Output:

Original array1: 10,20,-30,-40,30
Original array2: 10,20,-30,-40,30
New array: -30,30
هل كان المحتوى مفيد؟

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

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