4 ms·
I personally use a wraper around php's create_function to predefine upto 6 parameters and also return the last statement. function lambda( $code ) { if
by cninja 18y ago
I personally use a wraper around php's create_function to predefine upto 6 parameters and also return the last statement.
function lambda( $code )
{
if( !preg_match( '/return/', $code ) )
{
$code = preg_replace('/^(.*;(?!\s*$))?/s', "$1 return ", $code);
}
$code .= ';';
$response = create_function('$_=null,$_1=null,$_2=null,$_3=null,$_4=null,$_5=null', $code);
if( !$response )
{
error_log("lambda($code) failed");
}
return $response;
}
This converts:
$func = create_function('$v','return htmlenties($v,ENT_QUOTES);');
array_map($func, $data);
Into:
array_map(lambda('htmlenties($_, ENT_QUOTES)'), $data);