This question is basically an extension of my previous question:
How to subtract value of array but still in position
I have an input array of arrays. The values in each subarray always consist of values starting from 0
and without any gaps, values are incremented by one. However, the values are not necessarily in order AND I need to preserve this order while executing my required logic.
Next I have a blacklist of values that I wish to remove from all subarrays. Any original subarray value that exists in the blacklist array must be removed.
Sample input array of arrays:
$arrays = [
[0, 3, 10, 5, 6, 9, 2, 7, 1, 4, 8, 11],
[0, 1, 2, 3],
[0, 5, 2, 4, 3, 1],
[0, 1, 3, 2]
];
Sample blacklist array:
$deletes = [3, 5];
My desired output is:
[
[0, 8, 4, 7, 2, 5, 1, 3, 6, 9],
[0, 1, 2],
[0, 2, 3, 1],
[0, 1, 2],
]
All remaining values greater than 3
are reduced by 1
and values greater than 5
are reduced by 2
since I deleted 2
numbers.
If all numbers in a given subarray are less than all of the numbers in the blacklist array, then no change is required for that subarray.
I have a coding attempt here https://3v4l.org/lX2MP, but I am stuck when returning their values. All array values were combining.