We have an array of ranges in $r
:
$r = array( array(3,5), array(36,54) );
We want to add a new range to our ranges:
$n = array(11, 19);
We also want $r
to be sorted, so the new range should be inserted at position 1
. If we use array_splice
the result would be having 11
and 19
added as two new elements:
array_splice($r, 1, 0, $n);
// output: array( array(3,5), 11, 19, array(36,54) )
How can we get the desired result as shown below?
// output: array( array(3,5), array(11,19), array(36,54) )