/ Published in: PHP

To access a local variable within a callback, use currying (delayed argument binding).\r\nThe magic lies in this curry found here: http://www.sitepoint.com/forums/showthread.php?threadid=336758
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function curry($func, $arity) { \$args = func_get_args(); if(count(\$args) >= $arity) return call_user_func_array('$func', \$args); \$args = var_export(\$args, 1); return create_function('',' \$a = func_get_args(); \$z = ' . \$args . '; \$a = array_merge(\$z,\$a); return call_user_func_array(\'$func\', \$a); '); "); } function on_match($transformation, $matches) { } $callback = curry(on_match, 2); echo "\n"; ?>
URL: http://www.php.net/manual/en/function.preg-replace-callback.php#88000
Comments
