w3resource

PHP Exercises: Check if y is greater than x, and z is greater than y from three given integers x,y,z

PHP Basic Algorithm: Exercise-47 with Solution

Write a PHP program to check if y is greater than x, and z is greater than y from three given integers x,y,z.

Sample Solution:

PHP Code :

<?php
// Define a function that checks if $x is less than $y and $y is less than $z
function test($x, $y, $z)
{
    // Check if $x is less than $y AND $y is less than $z
    return $x < $y && $y < $z;
}

// Test the function with different sets of numbers
var_dump(test(1, 2, 3))."\n";
var_dump(test(4, 5, 6))."\n";
var_dump(test(-1, 1, 0))."\n";
?>

Explanation:

  • Function Definition:
    • The function test checks if the numbers follow a strictly increasing order, i.e., $x < $y and $y < $z.
  • Condition Checked:
    • Condition: It returns true if $x is less than $y and $y is less than $z; otherwise, it returns false.

Output:

bool(true)
bool(true)
bool(false)

Visual Presentation:

PHP Basic Algorithm Exercises: Check if y is greater than x, and z is greater than y from three given integers x,y,z.

Flowchart:

Flowchart: Check if y is greater than x, and z is greater than y from three given integers x,y,z.

PHP Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a PHP program to check if it is possible to add two integers to get the third integer from three given integers.
Next: Write a PHP program to check if three given numbers are in strict increasing order, such as 4 7 15, or 45, 56, 67, but not 4 ,5, 8 or 6, 6, 8.However,if a fourth parameter is true, equality is allowed, such as 6, 6, 8 or 7, 7, 7.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/php-exercises/basic-algorithm/php-basic-algorithm-exercise-47.php