小滕的博客

小滕的技术点滴

PHP洋葱模型

5 months ago · 0 MIN READ

<?php
$arr = [
function ($param, $callable) {
    $param *= 1;
    echo $param."\n";
    return $callable($param);
},
function ($param, $callable) {
    $param *= 2;
    echo $param."\n";
    return $callable($param);
},
function ($param, $callable) {
    $param *= 3;
    echo $param."\n";
    return $callable($param);
},
];

$onino = array_reduce(array_reverse($arr), function ($stack, $callable) {
    return function ($param) use ($stack, $callable) {
        return $callable($param, $stack);
    };
}, function ($param) {
    $param *= 4;
    echo "{$param}\n";
});

$onino(2);

Output:

2
4
12
48

近期小滕推出了 《Laravel源码分析课程》 喜欢的小伙伴可以去支持一下,感谢 ~

···

xiao teng



备案号:皖ICP备14012032号-5