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);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [0] => 0 [2] => 8 [4] => 4 [5] => 7 [6] => 2 [7] => 5 [8] => 1 [9] => 3 [10] => 6 [11] => 9 ) [1] => Array ( [0] => 0 [1] => 1 ) [2] => Array ( [0] => 0 [1] => 1 ) [3] => Array ( [0] => 0 [1] => 1 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
51.23 ms | 407 KiB | 5 Q