-2

So I have this:

$x=rand(0,100);
$y=rand(0,100);
$z=rand(0,100);

How can I put them in increasing order?

3 Answers3

1
$array = [rand(0,100), rand(0,100), rand(0,100)];
sort($array);
list($x, $y, $z) = $array;
wau
  • 386
  • 2
  • 8
0

As your questions reads like a homework I'll show you some code that generates the expected result but won't be a valid due.

$x = rand(0,100);
$y = rand(0,100);
$z = rand(0,100);

$numbers = [$x, $y, $z];

usort($numbers, function($left, $right) {
    return $left <=> $right;
});

array_walk($numbers, function($val) {
    echo $val . PHP_EOL;
});
kuh-chan
  • 1,157
  • 9
  • 16
-1

If you are using PHP7, they introduced the Spaceship Operator which could be useful for you.

What is <=> (the 'Spaceship' Operator) in PHP 7?

Update: There is actually a much easier answer than that. Put them in an array and use sort() on the array; http://php.net/manual/en/function.sort.php

Eric Brown
  • 854
  • 1
  • 10
  • 26