PHP How to access argument of function inside anonymous function? -
i need access first argument function inside anonymous function passed second argument said function. example:
<?php function a($arg, $func) { echo $func(); } a("argument 1", function () use($arg) {return $arg;}); ?>
the above return following error:
notice: undefined variable: arg in path/to/file.php on line 5
while desired result be:
argument 1
try below solution:
function a($arg, $func) { echo $func($arg); } a("argument 1", function ($arg) {return $arg;});
output
argument 1
for more detail have @ http://php.net/manual/en/functions.anonymous.php
Comments
Post a Comment