Can a function be passed as an argument in PHP? -
i wanting pass functon argument using php, in equivalent way jquery allows passing of functions.
jquery:
$("#foo").bind("click", function(){ alert("hello world!"); });
so, tried using php:
$arg1 = "hello"; $arg2 = function($name){echo $name;}; function call_me($func_arg1="", $func_arg2=""){ echo $func_arg1." ".$func_arg2("world!"); } call_me($arg1, $arg2);
... "world!hello" returned .... why return outcome backwards ?
ok, found answer. because trying echo echo! changed that:
$arg2 = function($name){return $name;};
this output "hello world!" expected.
Comments
Post a Comment