Q:

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

0

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

All Answers

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

<?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

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