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, ∼6303🔥, 0💬
Popular Posts:
What are "*..." and "**..." Wildcard Parameters in Function Definitions? If you want to define a fun...
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
Where to find tutorials on EPUB file format? I want to know how to create EPUB books. Here is a larg...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...
How To Remove Slashes on Submitted Input Values in PHP? By default, when input values are submitted ...