3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); $array = array(array('id' => 1, 'fid' => 2), array('id' => 2, 'fid' => 2)); class Map { public static function byProperty(array $array, $property) { $map = array(); foreach ($array as $record) { $propValue = self::_getPropertyValue($record, $property); $map[$propValue][] = $record; } return $map; } public static function byMultiProperty(array $array, array $properties) { $map = array(); $lastProperty = end($properties); foreach($array as $record) { $pointer = $map; foreach($properties as $property) { $propValue = self::_getPropertyValue($record, $property); if(!isset($pointer[$propValue])) { $pointer[$propValue] = array(); } $pointer = &$pointer[$propValue]; if($property === $lastProperty) { $pointer[] = $record; } } } return $map; } /** * @param mixed $record * @param string $property * @return mixed */ private static function _getPropertyValue($record, $property) { if (is_array($record)) { return isset($record[$property]) ? $record[$property] : null; } if (is_object($record)) { return isset($record->$property) ? $record->$property : null; } throw new InvalidArgumentException(sprintf('Unsupport record type: %s', gettype($record))); } } var_dump(Map::byMultiProperty($array, array('fid', 'id')));

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.3.60.0100.00718.31
8.3.50.0070.01222.95
8.3.40.0070.00718.87
8.3.30.0070.00719.09
8.3.20.0030.00620.21
8.3.10.0050.00321.85
8.3.00.0040.00419.68
8.2.180.0080.01116.75
8.2.170.0040.01122.96
8.2.160.0130.00720.35
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0050.00319.36
8.2.110.0000.00919.14
8.2.100.0060.00617.48
8.2.90.0040.00419.39
8.2.80.0080.00017.97
8.2.70.0000.00817.50
8.2.60.0000.00818.05
8.2.50.0030.00518.07
8.2.40.0040.00418.22
8.2.30.0070.00018.02
8.2.20.0040.00417.88
8.2.10.0060.00318.01
8.2.00.0000.00717.81
8.1.280.0170.00725.92
8.1.270.0050.00522.24
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0040.00423.88
8.1.230.0060.00617.77
8.1.220.0040.00417.74
8.1.210.0050.00318.77
8.1.200.0030.00617.35
8.1.190.0050.00517.36
8.1.180.0050.00318.10
8.1.170.0000.00818.46
8.1.160.0000.00821.94
8.1.150.0070.00018.84
8.1.140.0060.00317.47
8.1.130.0000.00817.95
8.1.120.0000.00717.38
8.1.110.0070.00017.44
8.1.100.0040.00417.38
8.1.90.0040.00417.37
8.1.80.0040.00417.37
8.1.70.0070.00017.41
8.1.60.0000.00817.62
8.1.50.0040.00417.57
8.1.40.0040.00417.55
8.1.30.0040.00417.59
8.1.20.0030.00617.64
8.1.10.0000.00717.54
8.1.00.0000.00717.54
8.0.300.0030.00619.02
8.0.290.0000.00816.63
8.0.280.0000.00818.34
8.0.270.0000.00717.13
8.0.260.0060.00017.33
8.0.250.0040.00417.02
8.0.240.0030.00316.98
8.0.230.0000.00716.97
8.0.220.0030.00316.80
8.0.210.0040.00416.98
8.0.200.0060.00016.86
8.0.190.0000.00817.00
8.0.180.0020.00516.95
8.0.170.0030.00516.94
8.0.160.0000.00716.83
8.0.150.0000.00816.80
8.0.140.0050.00316.91
8.0.130.0060.00013.30
8.0.120.0040.00416.86
8.0.110.0070.00016.89
8.0.100.0000.00716.98
8.0.90.0050.00216.77
8.0.80.0110.00716.89
8.0.70.0050.00316.80
8.0.60.0000.00716.96
8.0.50.0050.00316.86
8.0.30.0080.01316.94
8.0.20.0080.01317.40
8.0.10.0000.00816.92
8.0.00.0100.00716.73
7.4.330.0050.00015.02
7.4.320.0030.00316.53
7.4.300.0040.00416.55
7.4.290.0030.00316.57
7.4.280.0040.00416.55
7.4.270.0000.00716.63
7.4.260.0030.00316.51
7.4.250.0020.00516.39
7.4.240.0030.00316.49
7.4.230.0000.00716.52
7.4.220.0090.00916.48
7.4.210.0110.00416.61
7.4.200.0050.00316.60
7.4.160.0090.01316.52
7.4.150.0090.00917.40
7.4.140.0070.01517.86
7.4.130.0110.00716.71
7.4.120.0110.01016.60
7.4.110.0140.00416.38
7.4.100.0120.01216.35
7.4.90.0090.00916.60
7.4.80.0140.00419.39
7.4.70.0070.01016.63
7.4.60.0100.00716.43
7.4.50.0040.00416.57
7.4.40.0030.01416.41
7.4.30.0160.00616.51
7.4.00.0050.01215.12
7.3.330.0060.00013.37
7.3.320.0050.00013.29
7.3.310.0070.00016.35
7.3.300.0000.00816.31
7.3.290.0090.00816.40
7.3.280.0070.01116.40
7.3.270.0060.01017.40
7.3.260.0150.00616.66
7.3.250.0070.01116.45
7.3.240.0150.00616.28
7.3.230.0070.01016.39
7.3.210.0130.00316.38
7.3.200.0120.00919.39
7.3.190.0060.01116.47
7.3.180.0070.01016.43
7.3.170.0110.00816.34
7.3.160.0120.00416.50
7.3.120.0040.01415.05
7.3.110.0040.01314.86
7.3.100.0030.01414.80
7.3.90.0050.00514.97
7.3.80.0100.00314.80
7.3.70.0130.00314.71
7.3.60.0080.00414.93
7.3.50.0040.01114.88
7.3.40.0060.00914.98
7.3.30.0030.01414.75
7.3.20.0040.01216.74
7.3.10.0040.01116.74
7.3.00.0110.00316.40
7.2.330.0140.00516.88
7.2.320.0040.01216.88
7.2.310.0090.00916.70
7.2.300.0030.01316.79
7.2.290.0000.01816.73
7.2.250.0030.01715.09
7.2.240.0030.01315.00
7.2.230.0100.01015.19
7.2.220.0070.00715.09
7.2.210.0000.01615.00
7.2.200.0100.00714.74
7.2.190.0090.00615.05
7.2.180.0000.01515.14
7.2.170.0090.00615.02
7.2.60.0080.00416.67
7.2.00.0070.00719.08
7.1.330.0070.00715.87
7.1.320.0030.01415.82
7.1.310.0030.00615.64
7.1.300.0080.00815.90
7.1.290.0100.00315.96
7.1.280.0030.01015.80
7.1.270.0110.00015.84
7.1.260.0000.01715.87
7.1.200.0040.01115.86
7.1.100.0110.00018.45
7.1.70.0000.00717.30
7.1.60.0110.01119.34
7.1.50.0080.00317.01
7.1.00.0000.08022.45
7.0.200.0000.01016.61
7.0.140.0070.03322.09
7.0.60.0070.05719.97
7.0.50.0100.07717.89
7.0.40.0100.04720.25
7.0.30.0100.05020.26
7.0.20.0330.05320.38
7.0.10.0270.07720.15
7.0.00.0070.06720.22
5.6.280.0070.07321.03
5.6.210.0100.04320.54
5.6.200.0030.06018.27
5.6.190.0070.04020.61
5.6.180.0200.04020.57
5.6.170.0270.07720.55
5.6.160.0100.07320.50
5.6.150.0030.05718.18
5.6.140.0100.07718.29
5.6.130.0070.08018.27
5.6.120.0130.03721.00
5.6.110.0170.07721.10
5.6.100.0100.08321.10
5.6.90.0170.07720.96
5.6.80.0030.06320.37
5.6.70.0230.06720.38
5.5.350.0300.06720.48
5.5.340.0030.04717.97
5.5.330.0070.04020.44
5.5.320.0270.07720.13
5.5.310.0370.06320.34
5.5.300.0100.07017.99
5.5.290.0030.08317.97
5.5.280.0170.05020.75
5.5.270.0130.05020.96
5.5.260.0130.06020.78
5.5.250.0100.08020.56
5.5.240.0000.04020.17
5.4.450.0270.03719.38
5.4.440.0230.04719.41
5.4.430.0270.03319.55
5.4.420.0130.05719.32
5.4.410.0130.07018.97
5.4.400.0100.05318.63
5.4.390.0130.05318.62
5.4.380.0100.05718.86
5.4.370.0170.04718.57
5.4.360.0070.05318.77
5.4.350.0030.03713.78
5.4.340.0130.03313.87
5.4.320.0100.04314.50
5.4.310.0030.04014.34
5.4.300.0100.03714.39
5.4.290.0130.03314.28
5.4.280.0000.04014.15
5.4.270.0070.04714.16
5.4.260.0100.03714.16
5.4.250.0100.04314.10
5.4.240.0000.05314.14
5.4.230.0070.04014.23
5.4.220.0130.04314.18
5.4.210.0100.03314.10
5.4.200.0100.03314.09
5.4.190.0200.02314.21
5.4.180.0070.03714.21
5.4.170.0100.03314.10
5.4.160.0170.04314.40
5.4.150.0030.03714.17
5.4.140.0030.04313.79
5.4.130.0070.03313.80
5.4.120.0070.03313.79
5.4.110.0000.04313.71
5.4.100.0070.03313.73
5.4.90.0100.03313.90
5.4.80.0070.03713.79
5.4.70.0070.03313.86
5.4.60.0100.04013.80
5.4.50.0030.04313.76
5.4.40.0000.04014.00
5.4.30.0030.04013.77
5.4.20.0100.03313.76
5.4.10.0030.03713.77
5.4.00.0030.03713.27
5.3.290.0070.04014.84
5.3.280.0070.03714.57
5.3.270.0030.04014.66
5.3.260.0100.03714.61
5.3.250.0070.03714.66
5.3.240.0070.03714.54
5.3.230.0130.03314.58
5.3.220.0030.04314.57
5.3.210.0030.04714.62
5.3.200.0130.04314.57
5.3.190.0070.04314.64
5.3.180.0100.04014.71
5.3.170.0030.04714.52
5.3.160.0130.03014.73
5.3.150.0100.03714.72
5.3.140.0130.03314.76
5.3.130.0130.03314.50
5.3.120.0070.04014.70
5.3.110.0070.04314.57
5.3.100.0030.04014.04
5.3.90.0030.04014.02
5.3.80.0030.04014.02
5.3.70.0100.03314.01
5.3.60.0000.04314.13
5.3.50.0030.04013.92
5.3.40.0070.04014.00
5.3.30.0100.04013.99
5.3.20.0030.03713.76
5.3.10.0030.03713.69
5.3.00.0100.04013.63
5.2.170.0030.03311.08
5.2.160.0030.03011.15
5.2.150.0000.04711.10
5.2.140.0030.03711.15
5.2.130.0100.02311.10
5.2.120.0030.03011.08
5.2.110.0000.03711.16
5.2.100.0000.03311.23
5.2.90.0070.02711.05
5.2.80.0000.03711.15
5.2.70.0030.03011.09
5.2.60.0030.03010.99
5.2.50.0070.03011.02
5.2.40.0030.03311.05
5.2.30.0000.03311.02
5.2.20.0070.02710.95
5.2.10.0030.03010.92
5.2.00.0000.03710.74
5.1.60.0000.0309.98
5.1.50.0000.0309.98
5.1.40.0100.0309.95
5.1.30.0070.02710.33
5.1.20.0030.03010.53
5.1.10.0100.02010.16
5.1.00.0100.02310.05
5.0.50.0030.0208.56
5.0.40.0100.0138.50
5.0.30.0030.0338.36
5.0.20.0030.0208.15
5.0.10.0070.0178.32
5.0.00.0030.0378.29
4.4.90.0000.0205.87
4.4.80.0000.0275.85
4.4.70.0000.0175.98
4.4.60.0030.0205.83
4.4.50.0100.0175.84
4.4.40.0070.0235.80
4.4.30.0030.0135.99
4.4.20.0030.0175.87
4.4.10.0000.0176.05
4.4.00.0000.0305.84
4.3.110.0030.0135.82
4.3.100.0070.0105.83
4.3.90.0030.0135.77
4.3.80.0030.0235.90
4.3.70.0100.0075.77
4.3.60.0030.0135.72
4.3.50.0030.0135.79
4.3.40.0000.0275.70
4.3.30.0000.0174.50
4.3.20.0030.0134.59
4.3.10.0000.0174.44
4.3.00.0000.02016.49

preferences:
63.86 ms | 401 KiB | 5 Q