开发者

How do I sort a multidimensional hash array by a key maybe three levels in, in PHP?

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}}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜