PHPnews.io

Closure Binding as an alternative to “use” variables

Written by murze.be / Original link on Mar. 20, 2017

On his blog Mark Baker shares some thoughts on how to use closure binding to avoid having import variables with the use keyword.

You’ll learn how to rewrite

$filteredArrayData = array_filter(
    $arrayData,
    function($value) use ($minimumPrice, $maximumPrice) {
        return $value->price >= $minimumPrice && $value->price < $maximumPrice;
    }
);

to

$filteredArrayData = array_filter(
    $bookData,
    $priceFilter->inRange(5.00, 15.00)
);

https://markbakeruk.net/2017/03/12/closure-binding-as-an-alternative-to-use-variables/

The post Closure Binding as an alternative to “use” variables appeared first on murze.be.

murze

« Understanding Laravel’s HighOrder Collections - A collection of vue.js components »