3v4l.org

run code in 300+ PHP versions simultaneously
<?php $precision = 100000; $offset = 0; $prizes = [ ['name' => '1', 'chance' => '0.1'], ['name' => '2', 'chance' => '0.2'], ['name' => '3', 'chance' => '0.3'], ['name' => '4', 'chance' => '0.1'], ]; $reduce = $offset; foreach ($prizes as $index => $prize) { $prizes[$index]['min'] = $reduce; $reduce += $prize['chance'] * $precision; $prizes[$index]['max'] = $reduce; } var_dump($prizes);
Output for git.master, git.master_jit, rfc.property-hooks
array(4) { [0]=> array(4) { ["name"]=> string(1) "1" ["chance"]=> string(3) "0.1" ["min"]=> int(0) ["max"]=> float(10000) } [1]=> array(4) { ["name"]=> string(1) "2" ["chance"]=> string(3) "0.2" ["min"]=> float(10000) ["max"]=> float(30000) } [2]=> array(4) { ["name"]=> string(1) "3" ["chance"]=> string(3) "0.3" ["min"]=> float(30000) ["max"]=> float(60000) } [3]=> array(4) { ["name"]=> string(1) "4" ["chance"]=> string(3) "0.1" ["min"]=> float(60000) ["max"]=> float(70000) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
37.04 ms | 402 KiB | 8 Q