Re: sorting array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:  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.





-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux