3v4l.org

run code in 300+ PHP versions simultaneously
<?php $customer = ['name' => 'Peter', 'address' => ['street' => '5th', 'number' => 1969]]; /** * @param array $array * @param string $path A dot-separated property path. * @param mixed $default * @return mixed */ function getArrayValue(array $array, string $path, $default = null) { $parts = explode('.', $path); return array_reduce($parts, static function ($value, $part) use ($default) { return $value[$part] ?? $default; }, $array); } /** * @param string $path A dot-separated path, whose first part is a var name available in the global scope. * @param mixed $default * @return mixed */ function getGlobalArrayValue(string $path, $default = null) { @list($varName, $propertyPath) = explode('.', $path, 2); return getArrayValue($GLOBALS[$varName] ?? [], $propertyPath, $default); } echo getGlobalArrayValue('customer.name'), PHP_EOL; // Peter echo getGlobalArrayValue('customer.address.street'), PHP_EOL; // '5th' echo getGlobalArrayValue('customer.address.idontexist', 'somedefaultvalue'), PHP_EOL; // 'somedefaultvalue' echo getGlobalArrayValue('idontexist.address', 12); // 12

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.0110.00619.12
8.5.20.0090.00919.48
8.5.10.0070.01119.58
8.5.00.0060.00320.02
8.4.180.0080.01519.55
8.4.170.0130.00823.89
8.4.160.0110.01123.95
8.4.150.0030.00014.05
8.4.140.0120.00917.52
8.4.130.0060.00518.03
8.4.120.0110.00924.09
8.4.110.0140.00722.42
8.4.100.0110.00717.46
8.4.90.0090.01120.32
8.4.80.0140.00424.39
8.4.70.0100.00620.81
8.4.60.0130.00820.72
8.4.50.0150.00420.61
8.4.40.0040.01520.62
8.4.30.0110.00720.49
8.4.20.0110.00717.99
8.4.10.0100.01019.41
8.3.300.0140.00620.71
8.3.290.0140.00620.77
8.3.280.0120.00818.30
8.3.270.0110.00816.51
8.3.260.0060.00416.55
8.3.250.0130.00618.68
8.3.240.0090.00917.13
8.3.230.0110.00516.50
8.3.220.0050.00318.74
8.3.210.0040.00416.45
8.3.200.0120.00916.56
8.3.190.0130.00816.83
8.3.180.0090.01018.95
8.3.170.0080.00017.41
8.3.160.0030.00716.49
8.3.150.0110.00317.17
8.3.140.0110.00716.57
8.3.130.0080.00016.38
8.3.120.0060.00318.84
8.3.110.0100.00620.94
8.3.100.0050.00524.06
8.3.90.0030.00626.77
8.3.80.0030.00619.36
8.3.70.0160.00616.75
8.3.60.0090.01218.27
8.3.50.0050.00923.57
8.3.40.0170.00318.97
8.3.30.0120.00318.79
8.3.20.0040.00420.85
8.3.10.0090.00920.33
8.3.00.0090.00621.90
8.2.300.0130.00822.23
8.2.290.0130.00617.29
8.2.280.0080.00218.57
8.2.270.0130.00616.69
8.2.260.0070.01117.19
8.2.250.0050.00518.66
8.2.240.0090.00017.26
8.2.230.0120.00322.58
8.2.220.0040.00437.54
8.2.210.0070.00026.77
8.2.200.0030.00718.88
8.2.190.0120.00618.05
8.2.180.0110.00718.29
8.2.170.0090.00622.96
8.2.160.0040.01222.13
8.2.150.0090.00024.18
8.2.140.0140.00424.66
8.2.130.0150.00426.16
8.2.120.0040.00426.16
8.2.110.0050.00520.94
8.2.100.0090.00317.75
8.2.90.0000.00719.22
8.2.80.0030.00617.97
8.2.70.0110.00017.63
8.2.60.0000.00817.93
8.2.50.0040.00418.07
8.2.40.0050.00317.75
8.2.30.0000.00917.61
8.2.20.0000.00718.19
8.2.10.0000.00819.34
8.2.00.0050.00219.38
8.1.340.0140.00717.66
8.1.330.0110.00821.84
8.1.320.0120.00717.80
8.1.310.0040.00416.67
8.1.300.0060.00318.34
8.1.290.0060.01330.84
8.1.280.0130.00725.92
8.1.270.0080.00020.65
8.1.260.0040.00426.35
8.1.250.0150.00328.09
8.1.240.0030.00621.00
8.1.230.0040.00719.04
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0000.00917.47
8.1.190.0080.00017.36
8.1.180.0040.00418.10
8.1.170.0000.00818.66
8.1.160.0000.00718.82
8.1.150.0000.00818.90
8.1.140.0050.00322.07
8.1.130.0000.00720.16
8.1.120.0030.00317.46
8.1.110.0000.01117.39
8.1.100.0030.00717.39
8.1.90.0030.00617.48
8.1.80.0000.00717.47
8.1.70.0000.00717.52
8.1.60.0000.00817.58
8.1.50.0040.00417.55
8.1.40.0080.00017.41
8.1.30.0040.00417.57
8.1.20.0040.00717.67
8.1.10.0080.00017.61
8.1.00.0030.00517.59
8.0.300.0040.00418.77
8.0.290.0040.00416.75
8.0.280.0070.00018.56
8.0.270.0000.00717.87
8.0.260.0000.00720.18
8.0.250.0000.00716.88
8.0.240.0030.00316.98
8.0.230.0040.00416.93
8.0.220.0090.00016.82
8.0.210.0030.00516.89
8.0.200.0040.00416.97
8.0.190.0000.00716.96
8.0.180.0040.00416.95
8.0.170.0060.00616.83
8.0.160.0070.00016.85
8.0.150.0000.00716.84
8.0.140.0060.00316.90
8.0.130.0030.00313.30
8.0.120.0080.00016.86
8.0.110.0070.00016.75
8.0.100.0040.00416.70
8.0.90.0050.00316.80
8.0.80.0070.01016.86
8.0.70.0040.00416.84
8.0.60.0050.00316.73
8.0.50.0040.00416.72
8.0.30.0100.00717.07
8.0.20.0110.00716.99
8.0.10.0080.00016.98
8.0.00.0120.00616.95
7.4.330.0000.00515.55
7.4.320.0000.00716.55
7.4.300.0070.00016.52
7.4.290.0050.00316.46
7.4.280.0080.00016.60
7.4.270.0120.00016.62
7.4.260.0000.00716.56
7.4.250.0030.00316.54
7.4.240.0050.00316.54
7.4.230.0000.00716.54
7.4.220.0000.00716.62
7.4.210.0060.00916.56
7.4.200.0030.00316.63
7.4.130.0090.00916.59
7.4.120.0090.00916.52
7.4.110.0160.01016.48
7.4.100.0060.01016.72
7.4.90.0080.00816.41
7.4.80.0160.00919.39
7.4.70.0130.00316.57
7.4.60.0030.01416.48
7.4.50.0070.01016.42
7.4.40.0070.01016.61
7.4.00.0110.00414.77
7.3.330.0000.00716.41
7.3.320.0070.00013.23
7.3.310.0000.00716.27
7.3.300.0000.00616.38
7.3.290.0040.00416.37
7.3.280.0000.01416.27
7.3.260.0040.01316.50
7.3.240.0090.00816.47
7.3.230.0160.00616.52
7.3.210.0030.01416.40
7.3.200.0100.00716.38
7.3.190.0060.01116.33
7.3.180.0060.01016.57
7.3.170.0030.01516.59
7.3.160.0030.01416.40
7.3.120.0170.00414.66
7.3.110.0000.01614.84
7.3.100.0040.01214.62
7.3.90.0050.01014.71
7.3.80.0130.00414.96
7.3.70.0090.01414.55
7.3.60.0050.01114.79
7.3.50.0050.01114.48
7.3.40.0040.01114.60
7.3.30.0140.00314.55
7.3.20.0130.00614.89
7.3.10.0070.01114.68
7.3.00.0080.00814.74
7.2.330.0090.00916.79
7.2.320.0140.00416.43
7.2.310.0090.00916.65
7.2.300.0110.00616.81
7.2.290.0060.00916.71
7.2.250.0080.00815.02
7.2.240.0090.00914.81
7.2.230.0120.00514.82
7.2.220.0100.00714.92
7.2.210.0120.00615.13
7.2.200.0130.00815.04
7.2.190.0120.00615.07
7.2.180.0110.00714.58
7.2.170.0040.01615.04
7.1.330.0150.00414.10
7.1.320.0170.00013.79
7.1.310.0080.00814.12
7.1.300.0110.00413.63
7.1.290.0090.00913.91
7.1.280.0130.00313.74
7.1.270.0060.01013.94
7.1.260.0100.01013.78

preferences:
117.61 ms | 1408 KiB | 5 Q