DxDogo DxDogo - 1 year ago 139
PHP Question

php array skip values greater than X

I have an array with values between 1-100. However, in case of an error, is there a way to make one final check just to be sure I skip/ignore values greater than 100 and the output is between 1-100?

Answer Source

This is where array_filter() comes in handy.

$lower_limit = 1;
$upper_limit = 100;

$array = array_filter(
    function ($value) use ($lower_limit, $upper_limit) {
        return ($value >= $lower_limit && $value <= $upper_limit);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download