如何將此perl子例程轉換爲PHP函數?perl to php翻譯
sub disagreement {
my $disagreement = 0;
my %aggregate =() ;
foreach my $item (@_) {$aggregate{$item}++}
foreach my $cat_a (keys %aggregate) {
foreach my $cat_b (keys %aggregate) {
if ($cat_a != $cat_b) {$disagreement += $aggregate{$cat_a} * $aggregate{$cat_b} * &$distance_metric ($cat_a , $cat_b)}
}
}
$disagreement /= @_ * (@_ - 1) ;
return ($disagreement) ;
}
我這裏有一個問題:
foreach my $cat_a (keys %aggregate) {
foreach my $cat_b (keys %aggregate) {
}
}
在這個表達式中「&」的用途是什麼:「... *&$ distance_metric($ cat_a,$ cat_b)}」? – Alex 2010-03-16 15:11:06