我有这样的功能:
function test($str,$func) {
$func($str);
//Something more here
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在那里传递一个函数名?我想做test("Hello",strtolower);或喜欢test("Bye",sometextprocessfunc);
function test($str, $func){
return call_user_func($func,$str);
}
Run Code Online (Sandbox Code Playgroud)
像这样使用它
$asd = test("ASD","strtolower");
Run Code Online (Sandbox Code Playgroud)
与任何其他字符串一样
test("Hello","strtolower");
Run Code Online (Sandbox Code Playgroud)
查看变量函数
| 归档时间: |
|
| 查看次数: |
2695 次 |
| 最近记录: |