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 {$l开发者_运维技巧og{$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.
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}}
精彩评论