Classify variable contents in an increasing order : ' From small to big

Hello guys
i have this little problem with PHP
i have few variables for exemple
$Variable1 = 06
$Variable2 = 10
$Variable3 = 03
$Variable4 = 04
$Variable5 = 12

For exemple
now if i wanted to echo these variables in a table there should be no problem, considering that i’m using a loop
however, what i want to do is echo them in an inceasing way, in other words, i want the php to check the values of the variables and echo them from the smallest value to the biggest
in other words
instead of echoing :
06
10
03
04
12
it would check the values of the variables and echo them like this
03
04
06
10
12
and i don’t want to do it manually OFC
thanks in advance

Hello,

There isn’t a whole lot of information to go off of with your question but from what you’ve given I would suggest storing your variables in an array and then sort them. This will put them in ascending order.

[php]

<?php $Variable1 = 06; $Variable2 = 10; $Variable3 = 03; $Variable4 = 04; $Variable5 = 12; $vars = array($Variable1,$Variable2,$Variable3,$Variable4,$Variable5); sort($vars); foreach($vars as $variable){ echo $variable . '
'; } ?>

[/php]

Thanks for your help friend :slight_smile:

Well, I’m glad if it helped :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service