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, 4556🔥, 0💬
Popular Posts:
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to use the JSON to XML Conversion Tool at utilities-online.info? If you want to try the JSON to ...
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...