Q:

Write a PHP program to create an array taking two middle elements from a given array of integers of length even

0

Write a PHP program to create an array taking two middle elements from a given array of integers of length even

All Answers

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

<?php
function test($numbers)
 { 
    return [$numbers[sizeof($numbers) / 2 - 1], $numbers[sizeof($numbers) / 2]];
 }   

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

Sample Output:

New array: 7 9

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