3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function entropy($a, $b) { $options = array_filter(func_get_args()); $total = array_sum($options); $entropy = 0; foreach ($options as $size) { $part = $size / $total; $entropy -= $part * log($part, 2); } return $entropy; } var_dump('1 4', entropy(1, 4)); // abbbb echo "\n"; var_dump('2 2', entropy(2, 2)); // aabb echo "\n"; var_dump('2 2 2', entropy(2, 2, 2)); // aabbcc echo "\n"; var_dump('2 2 2 2', entropy(2, 2, 2, 2)); // aabbccdd echo "\n";
Output for 4.3.0 - 7.2.0
string(3) "1 4" float(0.72192809488736) string(3) "2 2" float(1) string(5) "2 2 2" float(1.5849625007212) string(7) "2 2 2 2" float(2)