3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ 1 => [ 11 => [ 111 => ['res_id' => 111, 'city_id' => 11, 'country_id' => 1], 112 => ['res_id' => 112, 'city_id' => 11, 'country_id' => 1], 113 => ['res_id' => 113, 'city_id' => 11, 'country_id' => 1], ], 12 => [ 121 => ['res_id' => 121, 'city_id' => 12, 'country_id' => 1], ], ], 2 => [ 21 => [ 212 => ['res_id' => 212, 'city_id' => 21, 'country_id' => 2], 214 => ['res_id' => 214, 'city_id' => 21, 'country_id' => 2], ], 22 => [ 221 => ['res_id' => 221, 'city_id' => 22, 'country_id' => 2], 222 => ['res_id' => 222, 'city_id' => 22, 'country_id' => 2], 223 => ['res_id' => 223, 'city_id' => 22, 'country_id' => 2], ], ], 3 => [ 31 => [ 312 => ['res_id' => 312, 'city_id' => 21, 'country_id' => 2], 314 => ['res_id' => 314, 'city_id' => 21, 'country_id' => 2], ], ] ]; function array_filter_clean(array $array, array $callbacks, $currentDepth = 0, $currentKey = '') { if (array_key_exists($currentDepth, $callbacks)) { // identify node to apply callback to $callback = $callbacks[$currentDepth]; if (!$callback($currentKey, $array)) { // empty node when callback returns false (or falsy) return []; } } foreach ($array as $key => &$value) { // &value to modify $array if (is_array($value)) { $value = array_filter_clean($value, $callbacks, $currentDepth+1, $key); // recurse if array } } return array_filter($array); // remove empty nodes (you may want to add "afterCallbacks" here) } $callbacksByDepth = [ /* 2 => function ($key, $value) { return $key > 20; }, */ 3 => function ($key, $value) { return $value['res_id']%2; }, ]; $output = array_filter_clean($input, $callbacksByDepth); print_r($output);

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.4.140.0140.00717.74
8.4.130.0090.00217.56
8.4.120.0120.00720.70
8.4.110.0150.00922.23
8.4.100.0120.00717.71
8.4.90.0110.00918.58
8.4.80.0110.00918.08
8.4.70.0040.00417.90
8.4.60.0160.00518.50
8.4.50.0160.00420.75
8.4.40.0070.01317.46
8.4.30.0000.00818.45
8.4.20.0130.00717.62
8.4.10.0130.00319.33
8.3.270.0120.00816.55
8.3.260.0100.00616.52
8.3.250.0070.00918.93
8.3.240.0100.01016.42
8.3.230.0060.00218.66
8.3.220.0100.00817.24
8.3.210.0080.00716.56
8.3.200.0070.00616.73
8.3.190.0110.00919.10
8.3.180.0120.00618.85
8.3.170.0140.00418.26
8.3.160.0070.01017.34
8.3.150.0050.00516.64
8.3.140.0040.00418.98
8.3.130.0080.00018.46
8.3.120.0150.00018.96
8.3.110.0080.00016.47
8.3.100.0060.00318.34
8.3.90.0080.00026.77
8.3.80.0000.01019.36
8.3.70.0120.00316.75
8.3.60.0140.00318.43
8.3.50.0090.00923.49
8.3.40.0100.00721.89
8.3.30.0180.00018.66
8.3.20.0040.00424.18
8.3.10.0040.00424.66
8.3.00.0080.00026.16
8.2.290.0050.00520.53
8.2.280.0120.00718.22
8.2.270.0120.00417.28
8.2.260.0150.00418.25
8.2.250.0080.00016.48
8.2.240.0000.00817.16
8.2.230.0060.00320.94
8.2.220.0050.00524.06
8.2.210.0000.00726.77
8.2.200.0030.00618.88
8.2.190.0080.00818.30
8.2.180.0160.00025.92
8.2.170.0120.00318.79
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0000.00824.66
8.2.130.0000.00726.16
8.2.120.0060.00326.35
8.2.110.0070.00319.39
8.2.100.0040.00817.59
8.2.90.0050.00318.22
8.2.80.0040.00417.97
8.2.70.0000.00817.50
8.2.60.0040.00417.50
8.2.50.0080.00018.05
8.2.40.0000.00820.01
8.2.30.0040.00418.19
8.2.20.0030.00618.00
8.2.10.0040.00419.23
8.2.00.0000.00719.22
8.1.330.0130.00523.94
8.1.320.0130.00616.31
8.1.310.0080.00016.03
8.1.300.0040.00417.96
8.1.290.0030.00930.84
8.1.280.0070.00725.92
8.1.270.0090.00022.14
8.1.260.0050.00228.09
8.1.250.0000.00728.09
8.1.240.0080.00322.14
8.1.230.0040.00822.68
8.1.220.0080.00017.77
8.1.210.0030.00618.95
8.1.200.0030.00617.48
8.1.190.0070.00417.23
8.1.180.0040.00418.10
8.1.170.0000.00818.64
8.1.160.0000.00718.85
8.1.150.0000.00818.85
8.1.140.0040.00418.89
8.1.130.0040.00420.00
8.1.120.0040.00417.50
8.1.110.0030.00617.41
8.1.100.0070.00017.34
8.1.90.0040.00417.46
8.1.80.0020.00517.44
8.1.70.0040.00417.39
8.1.60.0040.00417.49
8.1.50.0040.00417.54
8.1.40.0040.00417.58
8.1.30.0030.00517.66
8.1.20.0000.00917.60
8.1.10.0000.01117.46
8.1.00.0000.00817.40
8.0.300.0030.00520.04
8.0.290.0040.00416.63
8.0.280.0000.00718.36
8.0.270.0080.00018.00
8.0.260.0030.00318.44
8.0.250.0040.00416.91
8.0.240.0030.00316.93
8.0.230.0030.00316.82
8.0.220.0000.00816.82
8.0.210.0000.00716.76
8.0.200.0040.00416.78
8.0.190.0080.00016.99
8.0.180.0040.00416.79
8.0.170.0000.00916.79
8.0.160.0000.00716.91
8.0.150.0000.00716.80
8.0.140.0040.00416.83
8.0.130.0070.00013.35
8.0.120.0000.00816.88
8.0.110.0000.00816.77
8.0.100.0040.00416.79
8.0.90.0030.00516.88
8.0.80.0050.01116.87
8.0.70.0000.00816.76
8.0.60.0030.00516.81
8.0.50.0000.00716.70
8.0.30.0030.01416.98
8.0.20.0170.00617.11
8.0.10.0070.00016.90
8.0.00.0080.01116.73
7.4.330.0050.00015.55
7.4.320.0000.00716.36
7.4.300.0000.00716.36
7.4.290.0030.00316.57
7.4.280.0040.00416.58
7.4.270.0030.00316.52
7.4.260.0030.00313.34
7.4.250.0030.00316.46
7.4.240.0000.00716.49
7.4.230.0030.00316.70
7.4.220.0040.00316.45
7.4.210.0010.01316.58
7.4.200.0040.00416.42
7.4.130.0110.01116.54
7.4.120.0030.01516.55
7.4.110.0100.00716.48
7.4.100.0110.01216.48
7.4.90.0090.00916.59
7.4.80.0070.01116.56
7.4.70.0100.00716.60
7.4.60.0090.00916.45
7.4.50.0040.01416.41
7.4.40.0090.01216.47
7.4.30.0100.00716.57
7.4.20.0140.00316.56
7.4.10.0070.01016.64
7.4.00.0070.01016.53
7.3.330.0030.00316.41
7.3.320.0030.00313.45
7.3.310.0040.00416.41
7.3.300.0000.00616.38
7.3.290.0130.00516.32
7.3.260.0070.01716.61
7.3.240.0100.00716.55
7.3.230.0140.00316.61
7.3.220.0140.00816.48
7.3.210.0170.00516.52
7.3.200.0070.01016.33
7.3.190.0030.01316.71
7.3.180.0060.01516.54
7.3.170.0100.00716.53
7.3.160.0140.00316.38
7.3.150.0140.00316.51
7.3.140.0070.01016.32
7.3.130.0030.01416.65
7.3.120.0120.00616.35
7.3.110.0110.00516.16
7.3.100.0100.01016.40
7.3.90.0100.00616.23
7.3.80.0140.00316.55
7.3.70.0070.01016.42
7.3.60.0070.01116.41
7.3.50.0090.01016.51
7.3.40.0100.00716.50
7.3.30.0090.01216.40
7.3.20.0110.00716.39
7.3.10.0040.01516.34
7.3.00.0160.00416.31
7.2.340.0110.00716.72
7.2.330.0090.00916.80
7.2.320.0140.00716.66
7.2.310.0130.00316.45
7.2.300.0100.00716.47
7.2.290.0060.01116.91
7.2.280.0100.00716.53
7.2.270.0080.00816.68
7.2.260.0080.01016.73
7.2.250.0060.01216.64
7.2.240.0120.00616.68
7.2.230.0130.00316.88
7.2.220.0120.00616.40
7.2.210.0060.01116.61
7.2.200.0080.00816.55
7.2.190.0090.00916.69
7.2.180.0120.00616.77
7.2.170.0070.01116.79
7.2.160.0060.01616.75
7.2.150.0030.01616.61
7.2.140.0160.00316.63
7.2.130.0060.01216.63
7.2.120.0160.00316.66
7.2.110.0090.00916.55
7.2.100.0100.01016.70
7.2.90.0100.01016.73
7.2.80.0100.01016.78
7.2.70.0080.01116.73
7.2.60.0210.00416.66
7.2.50.0100.01016.72
7.2.40.0220.00316.69
7.2.30.0120.01216.63
7.2.20.0040.01516.87
7.2.10.0120.01216.74
7.2.00.0120.01216.65

preferences:
20.97 ms | 403 KiB | 5 Q