3v4l.org

run code in 300+ PHP versions simultaneously
<?php function subtract(&$arr,$selectedDeletedNumbers){ // pass by reference to edit the same copy of the array foreach($arr as $index => $val){ $low = 0;$high = count($selectedDeletedNumbers) - 1; $equal_found = false; while($low <= $high){ $mid = intval(($low + $high) / 2); if($selectedDeletedNumbers[$mid] > $val){ $high = $mid - 1; }else if($selectedDeletedNumbers[$mid] < $val){ $low = $mid + 1; }else{ $equal_found = true; unset($arr[$index]); // if equal value, delete it as it your need break; } } if(!$equal_found){ $arr[$index] -= $low; // delete the offset till where it is greater among your $selectedDeletedNumbers } } } $selectedDeletedNumbers = [3,5]; sort($selectedDeletedNumbers); // sort to be apply binary search later $arr = [[0, 3, 10, 5, 6, 9, 2, 7, 1, 4, 8, 11], [0, 1], [0, 1], [0, 1]]; foreach($arr as &$val){ // pass by reference to edit the same copy of the array subtract($val,$selectedDeletedNumbers); } print_r($arr);

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.120.0030.00620.92
8.3.110.0090.00320.94
8.3.100.0030.00516.52
8.3.90.0030.00526.77
8.3.80.0050.00519.36
8.3.70.0090.00916.63
8.3.60.0040.01118.43
8.3.50.0170.00323.72
8.3.40.0150.00618.97
8.3.30.0120.00918.79
8.3.20.0040.00424.18
8.3.10.0030.00624.66
8.3.00.0070.00026.16
8.2.240.0030.01317.18
8.2.230.0120.00022.58
8.2.220.0040.00424.06
8.2.210.0100.00726.77
8.2.200.0030.00718.88
8.2.190.0060.01216.75
8.2.180.0080.00825.92
8.2.170.0040.01119.07
8.2.160.0070.00722.96
8.2.150.0080.00025.66
8.2.140.0030.00624.66
8.2.130.0000.00726.16
8.2.120.0070.00021.12
8.2.110.0070.00320.94
8.2.100.0080.00417.91
8.2.90.0040.00417.81
8.2.80.0030.00618.22
8.2.70.0080.00017.50
8.2.60.0040.00417.63
8.2.50.0000.00817.38
8.2.40.0080.00019.78
8.2.30.0000.00819.38
8.2.20.0070.00018.23
8.2.10.0040.00419.31
8.2.00.0040.00419.36
8.1.290.0090.00030.84
8.1.280.0090.00925.92
8.1.270.0090.00923.99
8.1.260.0080.00026.35
8.1.250.0030.00528.09
8.1.240.0090.00021.05
8.1.230.0000.01120.68
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0040.00417.35
8.1.190.0000.00817.23
8.1.180.0000.00818.10
8.1.170.0100.00017.62
8.1.160.0030.00618.93
8.1.150.0000.00918.94
8.1.140.0030.00518.88
8.1.130.0000.00717.46
8.1.120.0030.00617.49
8.1.110.0000.00917.45
8.1.100.0040.00417.40
8.1.90.0030.00517.44
8.1.80.0030.00617.46
8.1.70.0070.00017.45
8.1.60.0000.00817.57
8.1.50.0000.00817.55
8.1.40.0040.00417.55
8.1.30.0000.00817.65
8.1.20.0000.00717.59
8.1.10.0100.00017.47
8.1.00.0030.00617.54
8.0.300.0040.00419.95
8.0.290.0040.00416.75
8.0.280.0040.00418.37
8.0.270.0030.00316.82
8.0.260.0030.00316.70
8.0.250.0000.00716.97
8.0.240.0050.00316.83
8.0.230.0070.00016.92
8.0.220.0040.00416.79
8.0.210.0000.00716.89
8.0.200.0000.00616.87
8.0.190.0000.00816.80
8.0.180.0040.00416.97
8.0.170.0050.00316.87
8.0.160.0040.00416.85
8.0.150.0050.00316.86
8.0.140.0000.00816.75
8.0.130.0000.00513.36
8.0.120.0000.00816.88
8.0.110.0000.00816.80
8.0.100.0000.00816.96
8.0.90.0080.00016.94
8.0.80.0070.00716.81
8.0.70.0040.00416.88
8.0.60.0000.00816.75
8.0.50.0000.00716.76
8.0.30.0140.00317.34
8.0.20.0220.00817.05
8.0.10.0040.00416.98
8.0.00.0030.01616.88
7.4.330.0020.00215.55
7.4.320.0030.00316.46
7.4.300.0030.00316.58
7.4.290.0040.00416.42
7.4.280.0000.00716.54
7.4.270.0070.00016.60
7.4.260.0030.00313.28
7.4.250.0030.00516.42
7.4.240.0030.00316.62
7.4.230.0030.00316.31
7.4.220.0040.00416.52
7.4.210.0080.00616.59
7.4.200.0070.00016.68
7.4.130.0060.01316.58
7.4.120.0050.01116.62
7.4.110.0130.00316.50
7.4.100.0140.00716.44
7.4.90.0060.01616.50
7.4.80.0180.00416.39
7.4.70.0150.00316.57
7.4.60.0090.00916.29
7.4.50.0150.00616.55
7.4.40.0060.01816.19
7.4.30.0150.00816.15
7.4.20.0060.01516.38
7.4.10.0150.00916.56
7.4.00.0030.01516.43
7.3.330.0040.00416.27
7.3.320.0000.00513.38
7.3.310.0030.00316.45
7.3.300.0040.00416.32
7.3.290.0090.00516.35
7.3.260.0080.01016.56
7.3.230.0030.01416.37
7.3.210.0000.01716.42
7.3.200.0100.00716.57
7.3.190.0100.01316.42
7.3.180.0200.00316.58
7.3.170.0070.01516.60
7.3.160.0090.01516.72
7.3.150.0150.00616.69
7.3.140.0070.01416.38
7.3.130.0120.00916.36
7.3.120.0070.01116.43
7.3.110.0140.00816.55
7.3.100.0110.01116.35
7.3.90.0120.01116.37
7.3.80.0080.00916.45
7.3.70.0130.00616.41
7.3.60.0090.00916.39
7.3.50.0150.00616.51
7.3.40.0120.00916.33
7.3.30.0100.01016.23
7.3.20.0120.01516.41
7.3.10.0140.00716.53
7.3.00.0230.00416.54
7.2.330.0060.01216.79
7.2.320.0190.00016.43
7.2.310.0060.01316.69
7.2.300.0080.01616.71
7.2.290.0060.01216.73
7.2.280.0130.01016.77
7.2.270.0150.00916.83
7.2.260.0100.01016.54
7.2.250.0070.01116.70
7.2.240.0160.00816.62
7.2.230.0120.01316.38
7.2.220.0120.01216.68
7.2.210.0190.00016.47
7.2.200.0030.02016.59
7.2.190.0090.00916.46
7.2.180.0060.01316.57
7.2.170.0060.01216.67
7.2.160.0140.00716.66
7.2.150.0170.01016.82
7.2.140.0090.01216.80
7.2.130.0110.01416.73
7.2.120.0100.01416.69
7.2.110.0130.01016.70
7.2.100.0200.00716.66
7.2.90.0200.01316.66
7.2.80.0170.00716.54
7.2.70.0080.01116.50
7.2.60.0100.01416.63
7.2.50.0150.01116.48
7.2.40.0060.02116.80
7.2.30.0100.01016.71
7.2.20.0100.01316.71
7.2.10.0040.01716.73
7.2.00.0130.01016.59

preferences:
35.23 ms | 403 KiB | 5 Q