Re: sorting array
| From: | Becoming Digital | Date: | Sat, 17 May 2003 00:08:13 +0000 |
| Subject: | Re: sorting array | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27840@lists.php.net to get a copy of this message | ||
The way you describe it, you're not sorting anything. This is a basic
search/replace algorithm. Try nesting your basic if() statement inside a for()
loop. Something like the below.
$arraySize = count( $league );
for ( $i=0; i<$arraySize; i++ ) {
if ( $league[i] == $cols['league'] )
$league[i] = i;
}
Your description was a bit confusing, so my code above might have some screwy
variable names, but you should get the idea. Check out the PHP Array functions
reference for more info.
http://www.php.net/manual/en/ref.array.php
Edward Dudlik
Becoming Digital
www.becomingdigital.com
----- Original Message -----
From: "Earl" <earl@caribsports.com>
To: "PHP-DB" <php-db@lists.php.net>
Sent: Friday, 16 May, 2003 16:06
Subject: [PHP-DB] sorting array
hey guys, I need a little assistance here.
I've got an array like the one below
==========================================
$league =
array("NFL"=>1,"NCAAF"=>2,"NBA"=>3,"NCAAB"=>4,"C_BASE"=>6,"NHL"=>7,"WNDA"=>8,"WC
S"=>9,"BOX"=>10,"PGA"=>11,"TENNIS"=>12,"ARENA"=>13,
"NASCAR"=>14,"CH_HOC"=>15,"NFE"=>16,"NCAAW"=>17,"CFL"=>18);
==========================================
what i am doing is querying a db and would like to replace the value with that
from the array.
eg.(
$cols['league'] has the value of (NFE)
i would like to sort through the array to replace (NFE) with the corresponding
value which is (16)
i can do this using the [ if , elseif, else ] but that would have my code to
long. i am only looking for the shortest way out.
Thanks in advance for any assistance.