Write a PHP program to create a new array swapping the first and last elements of a given array of integers and length will be least 1.
<?php function test($numbers) { $first = $numbers[0]; $numbers[0] = $numbers[sizeof($numbers) - 1]; $numbers[sizeof($numbers) - 1] = $first; return $numbers; } $result = test([1, 5, 7, 9, 11, 13] ); echo "New array, after swapping first and last elements: " . implode(',', $result);
Sample Output:
New array, after swapping first and last elements: 13,5,7,9,11,1
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