how to get filtered values from array like values between range 10-20. my array contain 10,15,18,25,88,20. i want to print only between range 10-20.
You can use array_filter
function range10_20($var) {
return ( $var >= 10 && $var <= 20 );
}
$input = array(10,15,18,25,88,20);
$output = array_filter($input, 'range10_20');
Or something like that:
$input = array(10,15,18,25,88,20);
$range = array(
'from' => 10,
'to' => 20
);
$output = array_filter($input, function ($element) use ($range) {
return ( $var >= $range['from'] && $var <= $range['to'] );
});