Tools, FAQ, Tutorials:
Accessing Global Variables inside a Function in PHP
How To Access a Global Variable inside a Function? in PHP?
✍: FYIcenter.com
By default, global variables are not accessible inside a function. However, you can make them accessible by declare them as "global" inside a function. Here is a PHP script on declaring "global" variables:
<?php ?> $intRate = 5.5; function myAccount() { global $intRate; print("Defined inside the function? ". isset($intRate)."\n"); } myAccount(); print("Defined outside the function? ". isset($intRate)."\n"); ?>
This script will print:
Defined inside the function? 1 Defined outside the function? 1
⇒ Function Returns Data by Value in PHP
⇐ Global Variables in Main Script in PHP
2016-12-08, 2568👍, 0💬
Popular Posts:
Where to find tutorials on HTML language? I want to know how to learn HTML. Here is a large collecti...
How to login to Azure API Management Publisher Portal 2017 version? If you have given access permiss...
Where is API Management Service on my Azure Portal? If your IT department has signed up for an Azure...
How to run CMD Commands in Dockerfile to change Windows Docker images? When building a new Windows i...
How to use the RSS Online Validator at w3.org? You can follow this tutorial to learn how to use the ...