help with arrays
| From: | Jim Long | Date: | Fri, 28 Feb 2003 00:45:06 +0000 |
| Subject: | help with arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137491@lists.php.net to get a copy of this message | ||
Hi,
Origninal Post:
> I have an array with an html link as key and different $vars as val:
>
> $list = array (
> '<a href="http://someplace.com/">some
> place</a>' => $vendor1_total,
> '<a
> href="http://anotherplace.com/">another
> place</a>' => $vendor2__total,
> [snip] etc..
>
> some vals are numeric and some vals are "n/a"
> asort works to sort the array as a string, however, I need to sort the
> numeric vals numeric, then have the n/a's go away or be output at the
> bottom of the sort.
Kevin Stone wrote: (THANKS)
> In order to sort the non "n/a" values you're going
> to have to build a separate array and perhaps this will simplfy the problem.
> So instead of what I suggested earlier.. loop the array and start TWO new
> arrays within the loop. One array for "n/a" values and one for non-"n/a"
> values. After the values are sorted to their separate arrays do
> asort($nonnavals); then concatonate the two arrays together using
> array_merge(), putting the "n/a" array second.
I can't fiqure out how to set up arrays inside the while loop.
Using this:
while (list ($key, $val) = each ($orderd_list)) {
if ($val == 'n/a'){
$no_plan_list = array ($key => $val);// need an array here for "n/a"
}else{
$plan_list = array ($key => $val);// need an array here for numeric vals
}
}
Thanks In Advance,
Jim Long