3v4l.org

run code in 300+ PHP versions simultaneously
<?php function validate_length ($options = ['min_length' => 1, 'max_length' => null], $filters = null) { return static function ($value = null) use ($options, $filters) { $len = strlen($value); if (isset($options['min_length']) && $len < $options['min_length']) { return false; } if (isset($options['max_length']) && $len > $options['max_length']) { return false; } if (null !== $filters) { return filter_var($value, ...$filters); //php 5.6+ array spread operator } return $value; }; } $a = [ 'a' => 'value', 'b' => '', 'c' => 'a@example.com', 'd' => 'This& is a 🍕 Test', ]; $email_filter = [FILTER_VALIDATE_EMAIL, ['flags' => FILTER_FLAG_EMAIL_UNICODE]]; $string_filter = [FILTER_SANITIZE_STRING, ['flags' => FILTER_FLAG_ENCODE_AMP | FILTER_FLAG_STRIP_HIGH]]; $result = filter_var_array ($a, [ 'a' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['max_length' => 4])], 'b' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['min_length' => 1])], 'c' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['min_length' => 1, 'max_length' => 20], $email_filter)], 'd' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(['min_length' => 1], $string_filter)], ]); var_dump($result);

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.130.0050.00518.92
8.3.120.0030.00620.97
8.3.110.0000.00920.94
8.3.100.0080.00024.06
8.3.90.0130.00626.77
8.3.80.0100.00017.13
8.3.70.0130.01317.25
8.3.60.0200.00019.18
8.3.50.0070.01524.80
8.3.40.0100.00619.32
8.3.30.0090.00619.50
8.3.20.0070.00324.18
8.3.10.0050.00324.66
8.3.00.0080.00026.16
8.2.250.0080.00317.32
8.2.240.0130.00719.47
8.2.230.0050.00522.58
8.2.220.0060.00337.54
8.2.210.0080.00826.77
8.2.200.0100.00017.25
8.2.190.0030.01317.38
8.2.180.0130.00725.92
8.2.170.0100.00719.43
8.2.160.0100.00622.96
8.2.150.0060.00325.66
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0040.00421.47
8.2.110.0040.00721.68
8.2.100.0000.01218.47
8.2.90.0000.00918.47
8.2.80.0030.00618.59
8.2.70.0030.00618.13
8.2.60.0000.01018.25
8.2.50.0040.00418.13
8.2.40.0030.00720.38
8.2.30.0030.00518.57
8.2.20.0040.00418.49
8.2.10.0040.00419.57
8.2.00.0030.00619.76
8.1.300.0140.00718.65
8.1.290.0030.00618.88
8.1.280.0070.01525.92
8.1.270.0080.00023.99
8.1.260.0060.00326.35
8.1.250.0090.00028.09
8.1.240.0100.00022.83
8.1.230.0110.00021.20
8.1.220.0030.00618.04
8.1.210.0030.00619.23
8.1.200.0060.00317.97
8.1.190.0060.00317.97
8.1.180.0000.00918.10
8.1.170.0050.00318.93
8.1.160.0080.00019.47
8.1.150.0040.00419.30
8.1.140.0040.00419.38
8.1.130.0050.00320.55
8.1.120.0060.00318.03
8.1.110.0030.00517.96
8.1.100.0000.00918.02
8.1.90.0080.00018.07
8.1.80.0120.00018.03
8.1.70.0040.00417.92
8.1.60.0030.00618.13
8.1.50.0080.00018.07
8.1.40.0030.00618.18
8.1.30.0030.00618.16
8.1.20.0050.00518.07
8.1.10.0050.00318.05
8.1.00.0040.00820.33
8.0.300.0000.00820.20
8.0.290.0040.00417.17
8.0.280.0040.00418.67
8.0.270.0000.00718.34
8.0.260.0020.00518.64
8.0.250.0000.00717.25
8.0.240.0040.00417.39
8.0.230.0070.00017.39
8.0.220.0070.00017.39
8.0.210.0000.00817.40
8.0.200.0000.00817.38
8.0.190.0090.00017.34
8.0.180.0040.00417.35
8.0.170.0090.00017.31
8.0.160.0030.00617.27
8.0.150.0000.00817.10
8.0.140.0000.00817.16
8.0.130.0030.00313.76
8.0.120.0080.00017.28
8.0.110.0080.00017.23
8.0.100.0000.00817.46
8.0.90.0000.00917.45
8.0.80.0050.01117.35
8.0.70.0040.00417.41
8.0.60.0040.00417.34
8.0.50.0000.00817.26
8.0.30.0110.00617.71
8.0.20.0060.01517.57
8.0.10.0040.00417.48
8.0.00.0140.00717.29
7.4.330.0000.00615.55
7.4.320.0030.00316.89
7.4.300.0040.00417.08
7.4.290.0000.00817.00
7.4.280.0080.00016.92
7.4.270.0030.00616.99
7.4.260.0030.00313.70
7.4.250.0040.00416.93
7.4.240.0040.00417.11
7.4.230.0030.00617.14
7.4.220.0040.00417.07
7.4.210.0100.00717.06
7.4.200.0050.00316.88
7.4.130.0060.01416.84
7.4.120.0110.01017.16
7.4.110.0090.01017.03
7.4.100.0120.00616.92
7.4.90.0120.00617.08
7.4.80.0060.01516.94
7.4.70.0160.00316.99
7.4.60.0110.01016.74
7.4.50.0150.00616.79
7.4.40.0200.00316.90
7.4.30.0180.00316.76
7.4.20.0100.01116.83
7.4.10.0090.01016.88
7.4.00.0100.00916.90
7.3.330.0060.00316.66
7.3.320.0000.00613.73
7.3.310.0030.00616.82
7.3.300.0040.00416.63
7.3.290.0060.00916.79
7.3.280.0070.01016.67
7.3.260.0160.01116.80
7.3.250.0120.00817.03
7.3.240.0150.00416.88
7.3.230.0120.00616.69
7.3.220.0160.00416.63
7.3.210.0070.01216.82
7.3.200.0070.01216.93
7.3.190.0140.00716.80
7.3.180.0070.01316.84
7.3.170.0130.00916.84
7.3.160.0100.01216.93
7.3.150.0130.00616.78
7.3.140.0080.01216.90
7.3.130.0110.00816.96
7.3.120.0150.00617.02
7.3.110.0130.00716.67
7.3.100.0160.00516.99
7.3.90.0150.00816.78
7.3.80.0110.00816.78
7.3.70.0120.01016.76
7.3.60.0150.00916.89
7.3.50.0100.00916.85
7.3.40.0140.00916.88
7.3.30.0110.00916.79
7.3.20.0130.00916.74
7.3.10.0120.01116.80
7.3.00.0170.00816.92
7.2.340.0210.00716.61
7.2.330.0100.01516.77
7.2.320.0140.00817.13
7.2.310.0160.00916.92
7.2.300.0190.00417.05
7.2.290.0110.01517.01
7.2.280.0110.01417.06
7.2.270.0140.01117.03
7.2.260.0150.00816.94
7.2.250.0140.01317.03
7.2.240.0150.00816.90
7.2.230.0120.01516.95
7.2.220.0140.01317.05
7.2.210.0130.01216.98
7.2.200.0150.01216.96
7.2.190.0120.01316.79
7.2.180.0100.01316.97
7.2.170.0140.01017.05
7.2.160.0150.01216.87
7.2.150.0150.01216.97
7.2.140.0240.00616.96
7.2.130.0120.01717.07
7.2.120.0110.01416.92
7.2.110.0160.00816.92
7.2.100.0120.01316.88
7.2.90.0130.01316.97
7.2.80.0170.00916.98
7.2.70.0120.01616.89
7.2.60.0190.01317.01
7.2.50.0420.01117.05
7.2.40.0170.01117.01
7.2.30.0150.01117.14
7.2.20.0140.01217.03
7.2.10.0170.00917.00
7.2.00.0160.00916.96

preferences:
62.21 ms | 403 KiB | 5 Q