w3resource

PHP Exercises: Check the largest number among three given integers

PHP Basic Algorithm: Exercise-18 with Solution

Write a PHP program to check the largest number among three given integers.

Sample Solution:

PHP Code :

<?php
// Define a function that takes three parameters and returns the maximum value among them
function test($x, $y, $z) 
{
  // Find the maximum value using the max function, first comparing $x and $y, and then comparing the result with $z
  $max = max($x, max($y, $z));
  return $max;
}

// Test the function with different sets of values
echo test(1, 2, 3)."\n";
echo test(1, 3, 2)."\n";
echo test(1, 1, 1)."\n";
echo test(1, 2, 2)."\n";
?>

Sample Output:

3
3
1
2

Visual Presentation:

PHP Basic Algorithm Exercises: Check if a string 'yt' appears at index 1 in a given string.

Flowchart:

Flowchart: Check if a string 'yt' appears at index 1 in a given string.

PHP Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a PHP program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string.
Next: Write a PHP program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.