将内容而不是变量传递给PHP函数
是否可以将非变量的内容传递给PHP函数,例如要在另一个函数中执行的循环或类似构造 下面是一个php版本,介绍了如何用javascript实现将内容而不是变量传递给PHP函数,php,function,foreach,Php,Function,Foreach,是否可以将非变量的内容传递给PHP函数,例如要在另一个函数中执行的循环或类似构造 下面是一个php版本,介绍了如何用javascript实现 function myFunction($content){ // something important that needs to be done before content $content // something important that needs to be done after content } m
function myFunction($content){
// something important that needs to be done before content
$content
// something important that needs to be done after content
}
myFunction({
foreach($things_we_have as $key => $val){
// Things to do in centre of the function
}
});
显然,这是行不通的。可以这样做吗?如果可以,如何做?您可以使用/作为函数的参数
例如:
function myFunction($closure)
{
// something important that needs to be done before content
$closure($thingsWeHave);
// something important that needs to be done after content
}
myFunction(function($thingsWeHave)
{
foreach($thingsWeHave as $key => $val){
// Things to do in center of the function
}
});
其他例子是和我是个白痴。在JS中也需要这样做。忘记了需要声明它是()中的函数