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
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?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
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال