Tools, FAQ, Tutorials:
Local Variables in a Function in PHP
What Is the Scope of a Variable Defined in a Function? in PHP?
✍: FYIcenter.com
The scope of a local variable defined in a function is limited with that function. Once the function is ended, its local variables are also removed. So you can not access any local variable outside its defining function. Here is a PHP script on the scope of local variables in a function:
<?php ?> function myPassword() { $password = "U8FIE8W0"; print("Defined inside the function? ". isset($password)."\n"); } myPassword(); print("Defined outside the function? ". isset($password)."\n"); ?>
This script will print:
Defined inside the function? 1 Defined outside the function?
⇒ Global Variables in Main Script in PHP
⇐ Returning an Array from a Function in PHP
2016-12-08, 1245👍, 0💬
Popular Posts:
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How to create a new API on the Publisher Dashboard of an Azure API Management Service? If you are ne...
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How to use the "set-body" Policy Statement for an Azure API service operation? The "set-body" Policy...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...