Re: Ok, I know this may sound like a stupid question...
| From: | Ignacio Vazquez-Abrams | Date: | Tue, 05 Dec 2000 23:11:31 +0000 |
| Subject: | Re: Ok, I know this may sound like a stupid question... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28773@lists.php.net to get a copy of this message | ||
On Tue, 5 Dec 2000, Boget, Chris wrote:
> but I've been trying to find *simple* logic to do
> this and I cannot seem to wrap my head around
> it...
>
> I have 4 variables that are dynamically assigned
> numerical values. Let's say, after all the dynamic
> assignement is completed, I end up with:
>
> $this = 13;
> $that = 9;
> $other = 27;
> $bob = 2;
>
> What is the simplest way to figure out what order
> those variables should go in ascending order....
> Without putting the above 4 variables in an array...
>
> I've got some code, but it's soooo long. Longer than
> it should be, I'm sure.
>
> Thanks for any help you can provide!
>
> Chris
>
<?php
...
$vars=Array
(
Array("this", 0),
Array("that", 0),
Array("other", 0),
Array("bob", 0)
);
$result=Array();
for ($i=0; $i<count($vars); ++$i)
{
$min=2147483647
reset($vars);
while (list($key,$val)=each($vars))
{
if (!$val[1] and ${$val[0]}<$min)
{
$minvar=$key;
$min=${$val[0]};
};
};
$result[]=$minvar;
$vars[$minvar][1]=1;
};
for ($i=0; $i<count($result); ++$i)
{
print("{${$vars[$result[$i]]}}<br>\n");
};
?>
Hey, you asked! :)
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>