3v4l.org

run code in 500+ PHP versions simultaneously
<?php class FlattenArray { private array $mapped = []; public function __construct(array $input) { $this->mapped = array_map(fn ($currentKey) => $this->mapRecursive(explode('_', $currentKey), $input[$currentKey]), array_keys($input)); } private function mapRecursive(array $keys, $value) { if (empty($keys)) return; return array_fill_keys( [array_shift($keys)], $this->mapRecursive($keys, $value) ?? $value ); } public function joinAndFlatten() { return $this->mapped; } } var_dump((new FlattenArray(['a_a' => '2', 'a_b' => '333', 'c_c' => '123']))->joinAndFlatten());

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.5.30.0070.00920.14
8.5.20.0120.00519.50
8.5.10.0110.00718.75
8.5.00.0110.01119.95
8.4.180.0130.00922.14
8.4.170.0090.01323.91
8.4.160.0130.00923.76
8.4.150.0090.00416.92
8.4.140.0120.00917.69
8.4.130.0060.00318.06
8.4.120.0100.01120.61
8.4.110.0120.00822.79
8.4.100.0060.00917.82
8.4.90.0130.00818.62
8.4.80.0140.00617.75
8.4.70.0130.00717.88
8.4.60.0110.00818.86
8.4.50.0080.01219.30
8.4.40.0070.00317.50
8.4.30.0000.00818.51
8.4.20.0160.00317.81
8.4.10.0080.00820.43
8.3.300.0150.00920.86
8.3.290.0110.01118.34
8.3.280.0160.00918.55
8.3.270.0120.00816.61
8.3.260.0100.00716.75
8.3.250.0090.00818.98
8.3.240.0090.00716.41
8.3.230.0070.00216.93
8.3.220.0110.00717.24
8.3.210.0100.00916.68
8.3.200.0070.00216.65
8.3.190.0100.00817.27
8.3.180.0100.01016.69
8.3.170.0060.01019.24
8.3.160.0160.00316.79
8.3.150.0120.00320.91
8.3.140.0070.01118.91
8.3.130.0040.00418.29
8.3.120.0040.01118.97
8.3.110.0040.00420.94
8.3.100.0150.00024.06
8.3.90.0040.00426.77
8.3.80.0060.00316.88
8.3.70.0110.00716.58
8.3.60.0090.00618.30
8.3.50.0140.00018.54
8.3.40.0080.01218.85
8.3.30.0120.00319.34
8.3.20.0050.00324.18
8.3.10.0080.00024.66
8.3.00.0080.00026.16
8.2.300.0140.00818.11
8.2.290.0100.01020.42
8.2.280.0020.00618.16
8.2.270.0000.01517.42
8.2.260.0110.00716.75
8.2.250.0040.00416.74
8.2.240.0080.00019.05
8.2.230.0030.00522.58
8.2.220.0030.01337.54
8.2.210.0070.00026.77
8.2.200.0030.00616.50
8.2.190.0030.01218.29
8.2.180.0090.00925.92
8.2.170.0110.00418.76
8.2.160.0140.00722.96
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0100.00026.16
8.2.120.0040.00426.16
8.2.110.0070.00320.52
8.2.100.0060.00320.52
8.1.340.0120.00917.64
8.1.330.0070.01123.76
8.1.320.0110.00916.41
8.1.310.0110.00718.57
8.1.300.0030.00620.06
8.1.290.0090.00030.84
8.1.280.0090.00625.92
8.1.270.0070.00723.99
8.1.260.0070.00026.35
8.1.250.0080.00028.09
8.1.240.0060.00318.57
8.1.230.0000.01020.25
8.1.50.0060.00217.47

preferences:
52.4 ms | 870 KiB | 5 Q