I have a global variable like
<?PHP
function PrintVariable($str){
global ${"check" . $str} = "some value";
echo $checkmap;
}
PrintVariable('map');
but I am getting this error:
Parse error: syntax error, unexpected '=', expecting ',' or ';' in C:\wamp\www\PHP\index.php on line 3
after removing the global
from the code everything work fine but I have to create global
at this function.
There is no combined "declare global and assign value" statement in php.
You'd have to do that in two steps, e.g.
<?php
function foo($str) {
global ${"check" . $str};
${"check" . $str} = "some value";
}
foo('bar');
echo $checkbar;
...but what you really should do is: avoid globals.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments