1Create a helpers.php file in your app folder and load it up with composer:
2
3"autoload": {
4 "classmap": [
5 ...
6 ],
7 "psr-4": {
8 "App\\": "app/"
9 },
10 "files": [
11 "app/helpers.php" // <---- ADD THIS
12 ]
13},
14
15After adding that to your composer.json file, run the following command:
16
17composer dump-autoload
18
1$callback = function ($value) {
2 return (is_numeric($value)) ? $value * 2 : 0;
3};
4
5$result = with(5, $callback);
6
7// 10
8
9$result = with(null, $callback);
10
11// 0
12
13$result = with(5, null);
14
15// 5