Skip to content

Instantly share code, notes, and snippets.

@skounis
Created April 2, 2021 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skounis/147eab6385e00389dbf4a9429aced930 to your computer and use it in GitHub Desktop.
Save skounis/147eab6385e00389dbf4a9429aced930 to your computer and use it in GitHub Desktop.
Access a variable in the parent scope from an anonymous function in PHP
$result = '';
fetch("SELECT title FROM tbl", function($r) use (&$result) {
$result .= $r['title'];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment