3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Placeholder{} function curry(callable $func, ... $curriedArgs) { return function(...$fulfillment) use ($func, $curriedArgs) { return $func(...array_merge(array_map(function($arg) use ($fulfillment) { if ($arg instanceof Placeholder) return array_shift($fulfillment); return $arg; }, $curriedArgs), $fulfillment)); }; }; $resultset = json_decode('[{ "id": 1, "gender": "Male", "name": "Matthew" }, { "id": 2, "gender": "Male", "name": "Willie" }, { "id": 3, "gender": "Female", "name": "Ann" }, { "id": 4, "gender": "Female", "name": "Margaret" }, { "id": 5, "gender": "Female", "name": "Marie" }]',TRUE); $filterGender = function($row,$gender){ return $row['gender']==$gender; }; $detectMen = curry($filterGender,(new Placeholder),'Male'); $detectWomen = curry($filterGender,(new Placeholder),'Female'); var_dump($detectMen(['gender'=>'Male'])); //works $getLadies = curry('array_filter',(new Placeholder),$detectWomen); var_dump($getLadies($resultset)); //does not work

preferences:
30.74 ms | 408 KiB | 5 Q