<?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);