PHP function use variable from outside

前端 未结 4 1423
眼角桃花
眼角桃花 2020-11-30 00:08
function parts($part) { 
    $structure = \'http://\' . $site_url . \'content/\'; 
    echo($tructure . $part . \'.php\'); 
}

This function uses a

4条回答
  •  無奈伤痛
    2020-11-30 00:44

    Alternatively, you can bring variables in from the outside scope by using closures with the use keyword.

    $myVar = "foo";
    $myFunction = function($arg1, $arg2) use ($myVar)
    {
     return $arg1 . $myVar . $arg2;
    };
    

提交回复
热议问题