tags:

views:

88

answers:

2

I am moving from Perl to PHP and am struggling to get my head around PHP sorting.

Here's what I have in Perl:

$log{'11111'}{'1'}{'20100102'}{'name'}='blah';
$log{'11111'}{'1'}{'20100101'}{'name'}='blah';
$log{'11111'}{'1'}{'20100103'}{'name'}='blah';

$cook='11111';

foreach $entry (sort {$log{$cook}{$a}{time} cmp $log{$cook}{$b}{time}} keys %{$log{$cook}}){
       ...
       }

Basically, I would have the same array structure in PHP but want to sort like I do above.

A: 

You need the usort function.

You'll provide it with a compare callback function which would do the job of

{$log{$cook}{$a}{time} cmp $log{$cook}{$b}{time}}
codaddict
A: 

Theres a function here that'll do it, scroll down to the comment from 'Dollar Hauler Admin' on 12-Mar-2010 06:10.

thebluefox