Connecting Tech Pros Worldwide Forums | Help | Site Map

problems sorting an array

Jochen Califice
Guest
 
Posts: n/a
#1: Jul 17 '05
hello ng!

got a problem sorting my multi-dimensional array. I have the following
situation of an array:

$fahrzeugarray[0]["fzid"]= "23"
$fahrzeugarray[0]["fzname"]="Audi TT"
$fahrzeugarray[1]["fzid"]= "34"
$fahrzeugarray[1]["fzname"]="VW Polo 1.2"
$fahrzeugarray[2]["fzid"]= "57"
$fahrzeugarray[2]["fzname"]="BMW Z3"

now i need to sort the array by 'fzname' before showing it. got to create
<SELECT> list with the 'fzid' as value and 'fzname' as text.
I use the following code to handle that but it doesn't work:

---------------------------------------------------------------------------------------
array_multisort($fahrzeugarray["fzname"]);
foreach($fahrzeugarray as $show_fza)
{
echo "<option
value='".$show_fza["fzid"]."'>".$show_fza["fzname"]."</option>";
}
---------------------------------------------------------------------------------------

when i start the script it shows the list without sorting it before. that's
a problem i try to solve sonce hours.
perhaps some one got an idea what is wrong with my script? :)

many thanks!

Jochen



Daniel Tryba
Guest
 
Posts: n/a
#2: Jul 17 '05

re: problems sorting an array


Jochen Califice <mail@boomboxx.de> wrote:[color=blue]
> now i need to sort the array by 'fzname' before showing it. got to create
> <SELECT> list with the 'fzid' as value and 'fzname' as text.
> I use the following code to handle that but it doesn't work:
>
> array_multisort($fahrzeugarray["fzname"]);
>
> when i start the script it shows the list without sorting it before. that's
> a problem i try to solve sonce hours.
> perhaps some one got an idea what is wrong with my script? :)[/color]

You read the manual page of array_multisort? It doesn't do what you
want, see http://php.net/usort example 2.

Closed Thread