3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Etc; /** * Determines whether any element of `$array` satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return boolean `TRUE` if any element satisfies `$predicate`, `FALSE` otherwise */ function array_any(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { return true; } } return false; } /** * Determines whether all elements of `$array` satisfy `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return boolean `TRUE` if all elements satisfy `$predicate`, `FALSE` otherwise */ function array_all(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { continue; } return false; } return true; } /** * Returns the first element value of `$array` that satisfies `$predicate` * * @param array $array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @param mixed $default [optional] The value to return if no elements satisfy `$predicate` * @return mixed The element value, `$default` otherwise */ function array_first(array $array, callable $predicate = null, $default = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { return $value; } } return $default; } /** * Returns the first element key of `$array` that satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return mixed The element key, `NULL` otherwise */ function array_first_key(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach ($array as $key => $value) { if ((boolean) $predicate($value, $key)) { return $key; } } return null; } /** * Returns the last element value of `$array` that satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @param mixed $default [optional] The value to return if no elements satisfy `$predicate` * @return mixed The element value, `$default` otherwise */ function array_last(array $array, callable $predicate = null, $default = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach (array_reverse(array_keys($array)) as $key) { $value = $array[$key]; if ((boolean) $predicate($value, $key)) { return $value; } } return $default; } /** * Returns the last element key of $array` that satisfies `$predicate` * * @param array $array The array * @param callable $predicate [optional] The predicate, accepting parameters `$value`, `$key`, returning `boolean` * @return mixed The element key, `NULL` otherwise */ function array_last_key(array $array, callable $predicate = null) { $predicate = $predicate? : function ($value) { return !empty($value); }; foreach (array_reverse(array_keys($array)) as $key) { $value = $array[$key]; if ((boolean) $predicate($value, $key)) { return $key; } } return null; } var_dump(array_last_key([null, 'a', null, 'b', null]));

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.01018.52
8.3.50.0140.00621.02
8.3.40.0110.00418.80
8.3.30.0090.00620.17
8.3.20.0080.00020.34
8.3.10.0030.00521.92
8.3.00.0030.00522.52
8.2.180.0160.00616.50
8.2.170.0040.01122.96
8.2.160.0110.00422.13
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0030.00626.16
8.2.120.0080.00019.77
8.2.110.0000.00922.27
8.2.100.0060.01117.64
8.2.90.0050.00319.36
8.2.80.0030.00619.38
8.2.70.0030.00517.38
8.2.60.0000.00818.03
8.2.50.0040.00418.07
8.2.40.0110.00018.21
8.2.30.0070.00019.47
8.2.20.0040.00417.70
8.2.10.0080.00017.77
8.2.00.0070.00017.66
8.1.280.0110.01125.92
8.1.270.0030.00623.99
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0090.00023.96
8.1.230.0040.00819.19
8.1.220.0050.00317.74
8.1.210.0000.00818.77
8.1.200.0060.00317.23
8.1.190.0040.00417.43
8.1.180.0000.00819.01
8.1.170.0000.00818.47
8.1.160.0100.00018.93
8.1.150.0040.00418.55
8.1.140.0040.00417.36
8.1.130.0020.00517.86
8.1.120.0040.00417.48
8.1.110.0050.00317.38
8.1.100.0000.00717.41
8.1.90.0000.00817.47
8.1.80.0040.00317.54
8.1.70.0040.00417.46
8.1.60.0000.01317.63
8.1.50.0080.00017.45
8.1.40.0030.00517.55
8.1.30.0000.00717.69
8.1.20.0060.00317.72
8.1.10.0000.00817.65
8.1.00.0000.00817.46
8.0.300.0000.00718.77
8.0.290.0040.00417.43
8.0.280.0000.00718.52
8.0.270.0000.00717.30
8.0.260.0030.00316.92
8.0.250.0080.00016.93
8.0.240.0000.00916.93
8.0.230.0040.00416.98
8.0.220.0070.00016.87
8.0.210.0030.00317.00
8.0.200.0040.00416.96
8.0.190.0000.00716.89
8.0.180.0050.00216.85
8.0.170.0050.00316.95
8.0.160.0000.00716.80
8.0.150.0070.00016.87
8.0.140.0040.00716.89
8.0.130.0000.00513.41
8.0.120.0000.00816.91
8.0.110.0040.00416.87
8.0.100.0050.00216.78
8.0.90.0040.00416.99
8.0.80.0040.01116.87
8.0.70.0070.00016.96
8.0.60.0000.00816.92
8.0.50.0040.00416.88
8.0.30.0120.00717.19
8.0.20.0100.00817.40
8.0.10.0040.00417.13
8.0.00.0100.01116.77
7.4.330.0000.00515.00
7.4.320.0030.00316.54
7.4.300.0030.00316.54
7.4.290.0030.00316.64
7.4.280.0040.00416.54
7.4.270.0000.00716.64
7.4.260.0030.00313.28
7.4.250.0030.00616.53
7.4.240.0060.00116.60
7.4.230.0030.00316.54
7.4.220.0060.01216.48
7.4.210.0060.01316.54
7.4.200.0070.00016.63
7.4.190.0070.00016.52
7.4.160.0110.00716.48
7.4.150.0150.00917.40
7.4.140.0110.00917.86
7.4.130.0100.00816.53
7.4.120.0150.00316.63
7.4.110.0090.00916.50
7.4.100.0100.00716.64
7.4.90.0140.00416.44
7.4.80.0170.00719.39
7.4.70.0000.01616.52
7.4.60.0070.01116.71
7.4.50.0080.00016.52
7.4.40.0070.00722.77
7.4.30.0030.01416.63
7.4.00.0130.00314.75
7.3.330.0000.00613.21
7.3.320.0000.00513.32
7.3.310.0030.00316.42
7.3.300.0060.00016.30
7.3.290.0070.00716.33
7.3.280.0100.00916.34
7.3.270.0170.00017.40
7.3.260.0140.00316.34
7.3.250.0050.01516.48
7.3.240.0100.00716.66
7.3.230.0130.00316.39
7.3.210.0110.01116.50
7.3.200.0110.00719.39
7.3.190.0050.01116.43
7.3.180.0090.00816.64
7.3.170.0060.01116.36
7.3.160.0060.01016.45
7.3.120.0030.00714.78
7.3.110.0060.00715.01
7.3.100.0070.01014.71
7.3.90.0090.00614.80
7.3.80.0060.00914.74
7.3.70.0040.01114.82
7.3.60.0040.00814.76
7.3.50.0030.00914.70
7.3.40.0060.00614.57
7.3.30.0100.00414.79
7.3.20.0080.00316.77
7.3.10.0080.00816.68
7.3.00.0030.00916.57
7.2.330.0060.01216.50
7.2.320.0100.00716.75
7.2.310.0190.00016.86
7.2.300.0070.01016.75
7.2.290.0130.00616.74
7.2.240.0030.00614.98
7.2.230.0120.00315.17
7.2.220.0000.01014.86
7.2.210.0070.01014.98
7.2.200.0130.00315.10
7.2.190.0090.00614.83
7.2.180.0030.01015.04
7.2.170.0060.01315.04
7.2.160.0100.00714.81
7.2.150.0090.00416.93
7.2.140.0030.01316.71
7.2.130.0090.00516.94
7.2.120.0040.00716.81
7.2.110.0050.01116.79
7.2.100.0050.00916.96
7.2.90.0070.00816.85
7.2.80.0090.00416.77
7.2.70.0030.00916.80
7.2.60.0130.00716.70
7.2.50.0030.01217.00
7.2.40.0070.00716.69
7.2.30.0080.00716.84
7.2.20.0050.01116.96
7.2.10.0110.00316.94
7.2.00.0050.01216.80
7.1.330.0060.00615.56
7.1.320.0080.00815.55
7.1.310.0040.00815.73
7.1.300.0090.00615.88
7.1.290.0030.01215.75
7.1.280.0080.00815.50
7.1.270.0000.01615.40
7.1.260.0040.01115.73
7.1.250.0060.00815.79
7.1.200.0060.00615.72
7.1.70.0030.00617.13
7.1.60.0150.00919.21
7.1.50.0220.01634.95
7.1.00.0000.07022.54
7.0.200.0030.00616.52
7.0.140.0100.06322.06
7.0.100.0270.07719.99
7.0.90.0130.07719.92
7.0.80.0130.07720.02
7.0.70.0200.06319.95
7.0.60.0070.07319.92
7.0.50.0100.08320.38
7.0.40.0170.07720.11
7.0.30.0070.07020.05
7.0.20.0200.07020.13
7.0.10.0070.08320.09
7.0.00.0170.06319.91
5.6.280.0100.06721.06
5.6.250.0100.08020.67
5.6.240.0070.07020.71
5.6.230.0130.08020.71
5.6.220.0030.08020.64
5.6.210.0200.06320.73
5.6.200.0130.08321.07
5.6.190.0130.07720.94
5.6.180.0030.09021.04
5.6.170.0070.08320.97
5.6.160.0170.06321.03
5.6.150.0130.08021.11
5.6.140.0130.05021.08
5.6.130.0200.07020.94
5.6.120.0170.07321.02
5.6.110.0070.08321.05
5.6.100.0170.07021.16
5.6.90.0170.07320.96
5.6.80.0130.07320.39
5.6.70.0070.08020.52
5.6.60.0100.07320.41
5.6.50.0000.08720.40
5.6.40.0070.08020.34
5.6.30.0070.08020.45
5.6.20.0030.08720.46
5.6.10.0000.07320.53
5.6.00.0070.07320.38
5.5.380.0100.08320.45
5.5.370.0030.08020.45
5.5.360.0070.07320.51
5.5.350.0100.08020.43
5.5.340.0100.07720.80
5.5.330.0000.07720.77
5.5.320.0030.08320.64
5.5.310.0100.08020.86
5.5.300.0170.06320.86
5.5.290.0070.07320.88
5.5.280.0100.07320.80
5.5.270.0130.08020.93
5.5.260.0100.07720.80
5.5.250.0070.04720.74
5.5.240.0070.08320.27
5.5.230.0030.08720.21
5.5.220.0070.08320.02
5.5.210.0030.08320.16
5.5.200.0070.08720.24
5.5.190.0070.08320.11
5.5.180.0070.08320.27
5.5.160.0100.07720.11
5.5.150.0130.07720.23
5.5.140.0030.08720.08
5.5.130.0030.07020.11
5.5.120.0070.08320.22
5.5.110.0070.06720.22
5.5.100.0130.07319.96
5.5.90.0100.04019.95
5.5.80.0030.05020.17
5.5.70.0070.03720.05
5.5.60.0000.04320.10
5.5.50.0100.03720.11
5.5.40.0030.04020.00
5.5.30.0030.04020.06
5.5.20.0070.03719.93
5.5.10.0000.04320.09
5.5.00.0030.04019.97
5.4.450.0030.07719.57
5.4.440.0070.08019.45
5.4.430.0030.08319.54
5.4.420.0070.08719.45
5.4.410.0100.06319.24
5.4.400.0070.08319.05
5.4.390.0030.08719.05
5.4.380.0100.04718.89
5.4.370.0070.05319.12
5.4.360.0000.08319.15
5.4.350.0130.06019.17
5.4.340.0230.06319.23
5.4.320.0000.08719.12
5.4.310.0170.06719.05
5.4.300.0070.05318.89
5.4.290.0070.05719.03
5.4.280.0100.08018.88
5.4.270.0000.08319.09
5.4.260.0070.08319.03
5.4.250.0100.07719.12
5.4.240.0100.03319.03
5.4.230.0070.03719.05
5.4.220.0030.04319.14
5.4.210.0100.03319.10
5.4.200.0070.03719.09
5.4.190.0000.04319.02
5.4.180.0030.03318.90
5.4.170.0000.06019.02
5.4.160.0100.06318.88
5.4.150.0000.03718.95
5.4.140.0030.06016.49
5.4.130.0070.03316.50
5.4.120.0030.03716.46
5.4.110.0070.03316.40
5.4.100.0000.03316.43
5.4.90.0070.03016.35
5.4.80.0030.03316.53
5.4.70.0030.03316.59
5.4.60.0030.03716.54
5.4.50.0030.04716.46
5.4.40.0070.03316.36
5.4.30.0030.03716.50
5.4.20.0070.05316.30
5.4.10.0030.03716.35
5.4.00.0000.04015.99
5.3.290.0100.06014.86
5.3.280.0030.04014.79
5.3.270.0000.04014.78
5.3.260.0100.03314.64
5.3.250.0070.04314.71
5.3.240.0100.02714.60
5.3.230.0030.03714.61
5.3.220.0000.04714.64
5.3.210.0100.02714.64
5.3.200.0030.03714.63
5.3.190.0000.05314.61
5.3.180.0070.06014.57
5.3.170.0000.04714.61
5.3.160.0070.05014.51
5.3.150.0030.03714.73
5.3.140.0030.03714.63
5.3.130.0100.04714.67
5.3.120.0030.03714.62
5.3.110.0100.07714.74
5.3.100.0130.04314.02
5.3.90.0000.04014.13
5.3.80.0000.05014.20
5.3.70.0070.03314.05
5.3.60.0030.06313.99
5.3.50.0070.02713.94
5.3.40.0070.06013.94
5.3.30.0030.04013.91
5.3.20.0070.04013.72
5.3.10.0030.03313.81
5.3.00.0030.03713.63
5.2.170.0130.01711.19
5.2.160.0000.03011.10
5.2.150.0000.03011.14
5.2.140.0000.03311.13
5.2.130.0070.05010.94
5.2.120.0000.02711.02
5.2.110.0030.02710.95
5.2.100.0000.03010.95
5.2.90.0000.03011.17
5.2.80.0000.03711.09
5.2.70.0000.03011.13
5.2.60.0000.03711.04
5.2.50.0100.05310.85
5.2.40.0030.06010.98
5.2.30.0030.04010.77
5.2.20.0000.03310.96
5.2.10.0000.04710.88
5.2.00.0100.07010.74
5.1.60.0030.03010.04
5.1.50.0100.04310.04
5.1.40.0130.0479.98
5.1.30.0030.05710.39
5.1.20.0070.05710.38
5.1.10.0100.0479.90
5.1.00.0030.06010.10
5.0.50.0030.0478.43
5.0.40.0000.0438.50
5.0.30.0030.0638.41
5.0.20.0030.0438.41
5.0.10.0100.0238.41
5.0.00.0070.0278.41
4.4.90.0000.0138.41
4.4.80.0030.0138.41
4.4.70.0030.0108.41
4.4.60.0000.0178.41
4.4.50.0030.0138.41
4.4.40.0000.0578.41
4.4.30.0030.0208.41
4.4.20.0030.0338.41
4.4.10.0070.0338.41
4.4.00.0030.0508.41
4.3.110.0100.0208.41
4.3.100.0000.0338.41
4.3.90.0030.0238.41
4.3.80.0000.0438.41
4.3.70.0100.0178.41
4.3.60.0100.0278.41
4.3.50.0070.0338.41
4.3.40.0070.0408.41
4.3.30.0000.0408.41
4.3.20.0000.0378.41
4.3.10.0000.0308.41
4.3.00.0000.0378.41

preferences:
42.35 ms | 401 KiB | 5 Q