Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

multi-dimensional array sorting

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

multi-dimensional array sorting

Postby Hadleigh » Wed Mar 12, 2003 9:13 am

Hi,

I have a multi-dimensional array such as this one:

$array[0]["name"]="foo";
$array[0]["url"]="foo";
$array[0]["type"]="foo";
$array[0]["order"]=1;

$array[1]["name"]="foo";
$array[1]["url"]="foo";
$array[1]["type"]="foo";
$array[1]["order"]=2;

$array[2]["name"]="foo";
$array[2]["url"]="foo";
$array[2]["type"]="foo";
$array[2]["order"]=3;

I want to sort on the value of the order array element so I achieve the following.

$array[2]["order"]=3;
$array[1]["order"]=2;
$array[0]["order"]=1;

Can anybody tell me how I do this please?

Thanks,

Hadleigh.
Hadleigh
New php-forum User
New php-forum User
 
Posts: 32
Joined: Tue Feb 04, 2003 10:32 am
Location: UK

Postby Romantik » Thu Mar 13, 2003 1:51 am

may be with for()
Romantik
New php-forum User
New php-forum User
 
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson

Postby Hadleigh » Thu Mar 13, 2003 1:56 am

Thanks, but I was hoping that there would be a function out there. Putting the amount of data that I have to sort into a 'for' loop will be very processor intensive and I'm suprised that a 'sort' (or one of the many others) doesn't do this, or am I wrong?

Hadleigh.
Hadleigh
New php-forum User
New php-forum User
 
Posts: 32
Joined: Tue Feb 04, 2003 10:32 am
Location: UK

Postby Romantik » Thu Mar 13, 2003 2:02 am

natsort must help you
Romantik
New php-forum User
New php-forum User
 
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron