So I have this:
$x=rand(0,100);
$y=rand(0,100);
$z=rand(0,100);
How can I put them in increasing order?
So I have this:
$x=rand(0,100);
$y=rand(0,100);
$z=rand(0,100);
How can I put them in increasing order?
$array = [rand(0,100), rand(0,100), rand(0,100)];
sort($array);
list($x, $y, $z) = $array;
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;
});
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