Function as array value

前端 未结 4 1386
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 19:31

I can\'t seem to find anything of this, and was wondering if it\'s possible to store a function or function reference as a value for an array element. For e.g.



        
4条回答
  •  感情败类
    2020-12-05 20:28

    PHP supports the concept of variable functions, so you can do something like this:

    function foo() { echo "bar"; }
    $array = array('fun' => 'foo');
    $array['fun']();
    

    Yout can check more examples in manual.

提交回复
热议问题