# Arranging 4 variables in increasing value

**URL:** <https://forum.kirupa.com/t/arranging-4-variables-in-increasing-value/14911>\
**Category:** flash\
**Created:** [March 4, 2003, 9:31am UTC](https://forum.kirupa.com/t/arranging-4-variables-in-increasing-value/14911 "2003-03-04T09:31:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thybalt](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@thybalt](https://forum.kirupa.com/u/thybalt)\
**Post date:** [March 4, 2003, 9:31am UTC](https://forum.kirupa.com/t/arranging-4-variables-in-increasing-value/14911/1 "2003-03-04T09:31:56Z")

</div>

Guys!

I have 4 variables: pos1, pos2, pos3, pos4

I want to arrange these four values in order of ascending values, and store them in variables number1, number2, number3, number4. It doesn’t matter if I know the values in pos1, pos2, pos3, pos4. I just want the smallest value to be stored in number1, and the largest to be number2.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 4, 2003, 9:37am UTC](https://forum.kirupa.com/t/arranging-4-variables-in-increasing-value/14911/2 "2003-03-04T09:37:46Z")

</div>

thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 4, 2003, 10:16am UTC](https://forum.kirupa.com/t/arranging-4-variables-in-increasing-value/14911/3 "2003-03-04T10:16:38Z")

</div>

Howdy…

I am not quite getting the meaning of that ‘thanks’… Did you solve the problem or not???

Anyways… You can use an array and its sort() function to get what you want to do… Of course there’s gotta be million ways of doing it… 😉

```php
pos1 = 5;
pos2 = 3;
pos3 = 7;
pos4 = 1;

tempArray = new Array();

for (i = 1 ; i <= 4 ; i++)
{
	tempArray.push(this["pos" + i]);
	trace("pos" + i + " = " + this["pos" + i]);
}
tempArray.sort();

trace("tempArray = " + tempArray);

for (i = 1 ; i <= 4 ; i++)
{
	this["number" + i] = tempArray.shift();
	trace("number" + i + " = " + this["number" + i]);
}

```

> pos1 = 5  
> pos2 = 3  
> pos3 = 7  
> pos4 = 1  
> tempArray = 1,3,5,7  
> number1 = 1  
> number2 = 3  
> number3 = 5  
> number4 = 7

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 4, 2003, 12:10pm UTC](https://forum.kirupa.com/t/arranging-4-variables-in-increasing-value/14911/4 "2003-03-04T12:10:55Z")

</div>

I accidentally pressed enter hence the 2nd post. Thanks CyanBlue =)=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 5, 2003, 3:36am UTC](https://forum.kirupa.com/t/arranging-4-variables-in-increasing-value/14911/5 "2003-03-05T03:36:31Z")

</div>

No problem… 😉
