Re: sort and maintain varible names
| From: | Jason Wong | Date: | Mon, 29 Apr 2002 16:35:59 +0000 |
| Subject: | Re: sort and maintain varible names | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95193@lists.php.net to get a copy of this message | ||
On Tuesday 30 April 2002 01:19, Jim Long wrote:
> I have a basic sort:
>
> $orderd_list = array ("$onec_rounded_total", "$aps_rounded_total",
> "$bo_rounded_total", "$cap3_rounded_total",
> "$cap3_rounded_total",
> "$cap_rounded_total", "$cfl_rounded_total", "$ecg_rounded_total",
> "$ldd_rounded_total", "$png_rounded_total", "$spr_rounded_total",
> "$ist917_rounded_total", "$tciac_rounded_total",
> "$tcicl_rounded_total",
> "$utl_rounded_total"); sort ($orderd_list);
> reset ($orderd_list);
> while (list ($key, $val) = each ($orderd_list)) {
> echo "[".$key."] = ".$val."<br>\n";
>
> It returns
>
> [0] = 4.90
> [1] = 4.99
> [2] = 5.06
> [3] = 5.60
> [4] = 6.00
> [5] = 6.00
> [6] = 6.90
> [7] = 6.90
> [8] = 6.95
> [9] = 7.00
> [10] = 9.00
> [11] = 10.50
> [12] = 11.00
> [13] = 11.26
> [14] = 13.10
>
> How do I maintain a varible name (for identification) in this output
> list ie:
>
> onec = 4.90 //from the varible $onec_rounded_total
> cfl = 4.99
> bo = 5.06
> and so on...
First you need to define your array so that it encapsulates some form of
identification:
$orderd_list = array ('onec_rounded_total' => $onec_rounded_total,
'aps_rounded_total' => $aps_rounded_total, ...);
Then use asort().
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
Welcome to Lake Wobegon, where all the men are strong, the women are pretty,
and the children are above-average.
-- Garrison Keillor
*/