I have two arrays :
$a = array(
array("begin"=>0, "end"=>200,"value"=>90),
array("begin"=>200, "end"=>600,"value"=>50),
array("begin"=>600, "end"=>1000,"value"=>90)
);
$b = array(
array("begin"=>-5, "end"=>50,"value"=>10),
array("begin"=>550, "end"=>590,"value"=>30)
);
Target, merging two arrays with the following criteria:
- merging the array $b into $a (called $result)
- if item in $b overlap with any item in array $a, it should cut the interval in $a
- for any two intervals with same "begin" & "end" after 2), it should choose the smaller value
The answer i would expected:
$result = array(
array("begin"=>-5, "end"=>50,"value"=>10),
array("begin"=>50, "end"=>200,"value"=>90),
array("begin"=>200, "end"=>550,"value"=>50),
array("begin"=>550, "end"=>590,"value"=>30),
array("begin"=>590, "end"=>600,"value"=>50),
array("begin"=>600, "end"=>1000,"value"=>90)
);
What would be the best way to accomplish this? Thank you everyone.