Write a PHP program to shift an element in left direction and return a new array
<?php function test($numbers) { $size = sizeof($numbers); $shiftNums = [$size]; for ($i = 0; $i < $size; $i++) { $shiftNums[$i] = $numbers[($i + 1) % $size]; } return $shiftNums; } $result = test([10, 20, -30, -40, 50] ); echo "New array: " . implode(',', $result);
Sample Output:
New array: 20,-30,-40,50,10
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer