I am trying to extract the keys of an array as variables. I have following code for that:
01 | $array = [
02 | "bantya" => "BANTYA",
03 | "sontya" => "SONTYA",
04 | "niltya" => "NILTYA"
05 | ];
06 |
07 | function makeVar ($array) {
08 | foreach ($array as $key => $value) {
09 | $$key = $value;
10 | }
11 | echo $bantya;
12 | }
13 |
14 | makeVar($array);
15 | echo $bantya;
The problem is, line 11 echoes "BANTYA" correctly, but the same about line 15 is not true. It says :
Notice: Undefined variable: bantya in file\path on line 15
My question is, why is it showing this error? How can I make line 15 to output "BANTYA" (which is outside of the scope of function makeVar($array)
) globally after makeVar
function is declared?
Thanks in advance..