Q:

Write a PHP program to reverse a given array of integers and length 5

0

Write a PHP program to reverse a given array of integers and length 5.

All Answers

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

<?php
function test($nums)
 { 
      return [$nums[4], $nums[3], $nums[2], $nums[1], $nums[0]];
    
 }   

$a = [10, 20, -30, -40, 50];

echo "Original array: " . implode(',', $a) . "\n";

$result = test($a);

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

Sample Output:

Original array: 10,20,-30,-40,50
Reverse array: 50,-40,-30,20,10

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