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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -