Perl中的{$ histogram {$ value} ++}是什么意思? [英] What does {$histogram{$value}++} mean in Perl?

查看:133
本文介绍了Perl中的{$ histogram {$ value} ++}是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 子直方图{#数组元素的计数
my%histogram =();
foreach my $ value(@_){$ histogram {$ value} ++}
return(%histogram);
}

我正在尝试将Perl脚本翻译成PHP, (我真的不知道Perl的任何内容,但是我正在尝试)。

那么如何将这个 {$直方图{$ value} ++} 转换成PHP?



谢谢!

解决方案

 <?php 
$ histogram = array_count_values($ array);
?>


The whole subroutine for the code in the title is:

sub histogram { # Counts of elements in an array
  my %histogram = () ;
  foreach my $value (@_) {$histogram{$value}++}
  return (%histogram) ;
}

I'm trying to translate a Perl script to PHP and I'm having difficulties with it (I really don't know anything of Perl but I'm trying).

So how do I put this {$histogram{$value}++} into PHP?

Thanks!

解决方案

<?php
  $histogram = array_count_values($array);
?>

这篇关于Perl中的{$ histogram {$ value} ++}是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆