74.4k views
0 votes
Create a php user defined function called MinMax. The function accepts two numbers as arguments and it returns the string: "The minimum number is x and the maximum number is y" where x and y are the minimum and the maximum numbers respectively. For example, if the numbers 20 and 4 are passed to the function MinMax, it should return the string:

1 Answer

4 votes

Answer:

<?php

function MinMax($x,$y) {

if($x > $y){

echo("The minimum is ".$y." and the maximum number is ".$x);

}

else{

echo("The minimum is ".$x." and the maximum number is ".$y);

}

}

MinMax(20,4);

?>

Step-by-step explanation:

<?php

This defines the user function with two parameters x and y

function MinMax($x,$y) {

This checks if parameter x is greater than parameter y

if($x > $y){

If yes, it prints x as the maximum and y as the minimum

echo("The minimum is ".$y." and the maximum number is ".$x);

}

If otherwised

else{

If yes, it prints y as the maximum and x as the minimum

echo("The minimum is ".$x." and the maximum number is ".$y);

}

}

This calls the function

MinMax(20,4);

?>

User Franklins
by
5.6k points