开发者

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

开发者 https://www.devze.com 2022-12-26 15:45 出处:网络
I am moving from Perl to PHP and am struggling to get my head around PHP sorting. Here\'s what I have in Perl:

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

精彩评论

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

关注公众号