3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_pick(array $array, bool $weighted = false) { $weight = function($value, int $weight = 1){ $item = new class($value, $weight){ public function __construct($value, int $weight){ $this->value = $value; $this->weight = $weight; } }; return $item; }; foreach($array as $key => $value){ if($weighted){ $items[] = $weight($key, $value); } else { $items[] = $weight($value); } } $max = array_reduce($items, function($c, $i){ $c += $i->weight; return $c; }); $rand = rand(1, $max); foreach($items as $item) { $rand -= $item->weight; if ($rand <= 0) { return $item->value; } } } $array = str_split('qwertyuiopasdfghjklzxcvbnm'); var_dump(array_pick($array));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.2.20.0120.01117.77
7.2.10.0090.01318.04
7.2.00.0120.01218.00
7.1.140.0120.01016.95
7.1.130.0090.01116.84
7.1.120.0090.00916.73
7.1.110.0060.01416.23
7.1.100.0120.01416.10
7.1.90.0090.01116.25
7.1.80.0100.00916.00
7.1.70.0100.01015.29
7.1.60.2260.01333.21
7.1.50.0320.01132.93
7.1.40.0230.01532.66
7.1.30.0280.01432.69
7.1.20.0520.01233.00
7.1.10.0100.01314.67
7.1.00.0050.01314.82

preferences:
23.79 ms | 400 KiB | 5 Q