Q:

Write a PHP program to find out the maximum element between the first or last element in a given array of integers

0

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.

All Answers

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

<?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

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