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, 4475🔥, 0💬
Popular Posts:
What are "*..." and "**..." Wildcard Parameters in Function Definitions? If you want to define a fun...
FYIcenter.com Online Tools: FYIcenter JSON Validator and Formatter FYIcenter JSON to XML Converter F...
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How To Avoid the Undefined Index Error in PHP? If you don't want your PHP page to give out errors as...
How to use the "forward-request" Policy Statement to call the backend service for an Azure API servi...