How do I immediately execute an anonymous function in PHP?

前端 未结 9 1016
离开以前
离开以前 2020-11-27 03:29

In JavaScript, you can define anonymous functions that are executed immediately:

(function () { /* do something */ })()

Can you do somethin

9条回答
  •  半阙折子戏
    2020-11-27 03:48

    I tried it out this way, but it's more verbose than the top answer by using any operator (or function) that allows you to define the function first:

        $value = $hack == ($hack = function(){
                // just a hack way of executing an anonymous function
                return array(0, 1, 2, 3);                
        }) ? $hack() : $hack();
    

提交回复
热议问题