Q:

Write a PHP program to rotate the elements of a given array of integers (length 4 ) in left direction and return the new array

0

Write a PHP program to rotate the elements of a given array of integers (length 4 ) in left direction and return the new array

All Answers

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

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

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

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

$result = test($a);

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

Sample Output:

Original array: 10,20,-30,-40
Rotated array: 20,-30,-40,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