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, ∼5684🔥, 0💬
Popular Posts:
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
How to create Hello-3.1.epub with WinRAR? I have all required files to create Hello-3.1.epub. To cre...
Where to find tutorials on JSON (JavaScript Object Notation) text string format? I want to know how ...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...