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 use Monolog in PHP Symfony?
- How to connect to MySQL in PHP Symfony?
- How to use websockets in PHP Symfony?
- How to generate QR Code in PHP Symfony?
- How to upload a file in PHP Symfony?
- How to do validation in PHP Symfony?
- How to send emails in Symfony with PHP?
- How to use mutex in PHP Symfony?
- How to run a command in PHP Symfony?
- How to use the Query Builder in PHP Symfony?
See more codes...