Write a PHP program to find out the maximum element between the first or last element in a given array of integers ( length 4), replace all elements with maximum element.
<?php function test($nums) { $max = max($nums); return [$max, $max, $max, $max]; } $a = [10, 20, -30, -40]; echo "Original array: " . implode(',', $a) . "\n"; $result = test($a); echo "New array with maximum values: " . implode(',', $result);
Sample Output:
Original array: 10,20,-30,-40 New array with maximum values: 20,20,20,20
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