Skip to content

Instantly share code, notes, and snippets.

@jimmyadaro
Created May 1, 2019 15:25
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 jimmyadaro/46973468c36f47e591d7ba5b060079d3 to your computer and use it in GitHub Desktop.
Save jimmyadaro/46973468c36f47e591d7ba5b060079d3 to your computer and use it in GitHub Desktop.
Use an array key as a new variable
<?php
$my_array = array(
"foo" => "bar",
"quick" => "fox"
);
foreach($my_array as $k => $v) {
${$k} = $v;
}
echo $foo; //Return: "bar"
echo "<br />";
echo $quick; //Return: "fox"
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment