Created
May 1, 2019 15:25
-
-
Save jimmyadaro/46973468c36f47e591d7ba5b060079d3 to your computer and use it in GitHub Desktop.
Use an array key as a new variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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