w3resource

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


47. Increasing Order Check for x,y,z

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.

For more Practice: Solve these Related Problems:

  • Write a PHP script to determine if three integers are in strictly increasing order (x < y < z).
  • Write a PHP function to verify that the second number is greater than the first and the third is greater than the second using conditional operators.
  • Write a PHP program to check the ordering of three numbers and return a boolean confirming proper ascending order.
  • Write a PHP script to compare three inputs and output true only if they are arranged in increasing sequence, using comparison chains.

Go to:


PREV : Two Integers Sum to Third Check.
NEXT : Strict Increasing Order, Allow Equality Option.

PHP Code Editor:



Contribute your code and comments through Disqus.

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.