Find the range values between another range values,
Below code is working fine, But i need any other optimized way.
$lmi = 1000;
$lmx = 20000;
$cmi = 19000;
$cmx = 40000;
$cnt = count(array_intersect(range($lmi,$lmx),range($cmi,$cmx)));
If you are trying to compute the amount of overlap, try:
$overlap = ($lmx < $cmi || $cmx < $lmi) ? 0 : min($lmx-$cmi, $cmx-$lmi); print_r($overlap);
This returns zero if there is no overlap and the amount of overlap otherwise.