3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ArrayKeyable { public function toArrayKey(): string|int; } final class MyObject implements ArrayKeyable { public function __construct( public readonly int $id, public readonly string $name, ) {} public function toArrayKey(): string { return $this->name; } } $objects = []; $data = [[1, 'Jane'], [2, 'John'], [3, 'Jake'], [4, 'Jane']]; foreach($data as [$id, $name]) { $object = new MyObject($id, $name); $objects[$object->toArrayKey()][] = $object; // would turn into $objects[$object][] = $object; } var_dump($objects);

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)
8.4.140.0110.01017.66
8.4.130.0130.00817.61
8.4.120.0100.01022.20
8.4.110.0110.00918.66
8.4.100.0120.01117.56
8.4.90.0150.00618.39
8.4.80.0110.00917.66
8.4.70.0100.01017.97
8.4.60.0130.00819.03
8.4.50.0100.01119.48
8.4.40.0100.01020.55
8.4.30.0130.00618.77
8.4.20.0100.01020.57
8.4.10.0090.00024.06
8.3.260.0120.00716.69
8.3.250.0080.00918.70
8.3.240.0110.00816.64
8.3.230.0120.00816.60
8.3.220.0110.00817.05
8.3.210.0120.00716.73
8.3.200.0060.00316.42
8.3.190.0040.00519.16
8.3.180.0120.00516.47
8.3.170.0140.00718.88
8.3.160.0120.00618.41
8.3.150.0100.01018.82
8.3.140.0110.00416.49
8.3.130.0040.00418.26
8.3.120.0090.00019.17
8.3.110.0060.00320.94
8.3.100.0040.00416.52
8.3.90.0080.00016.85
8.3.50.0080.00016.73
8.2.290.0100.00620.69
8.2.280.0110.00418.48
8.2.270.0000.00918.28
8.2.260.0070.01020.75
8.2.250.0040.00416.63
8.2.240.0040.00417.20
8.2.230.0060.00322.58
8.2.220.0030.00616.39
8.2.210.0060.00318.28
8.2.50.0070.00719.52
8.1.330.0110.00820.54
8.1.320.0130.00616.07
8.1.310.0130.00616.81
8.1.300.0060.00318.04

preferences:
60.27 ms | 403 KiB | 5 Q