php-symfonyHow to set a global variable in PHP Symfony?
A global variable in PHP Symfony can be set using the $GLOBALS
array. This array is a superglobal variable which is available in all scopes throughout a script.
$GLOBALS['my_var'] = 'Hello World';
echo $GLOBALS['my_var'];
Output example
Hello World
$GLOBALS
: This is a superglobal array which is available in all scopes throughout a script.$GLOBALS['my_var']
: This is the global variable which is being set.'Hello World'
: This is the value of the global variable.echo $GLOBALS['my_var']
: This is used to output the value of the global variable.
Helpful links
More of Php Symfony
- How to generate a model in PHP Symfony?
- How to install Symfony on Windows?
- How to install PHP Symfony on Ubuntu?
- How to create a model in PHP Symfony?
- How to use Twig in Symfony with PHP?
- How to implement pagination in PHP Symfony?
- How to check PHP Symfony version?
- How to use Swagger with Symfony and PHP?
- How to use websockets in PHP Symfony?
- How to use the PHP Symfony findBy method?
See more codes...