How to use $GLOBALS variable in php to access global variables

Access global variable in php via any function/class using $GLOBALS inside, outside of scope.


Php $GLOBALS variable is used to retrieve any already declared global variable because inside php scripting programming language there are all global variables defines in $GLOBALS[index] form, So if you define any global variable in php then it will automatically set into index value and can be call through $GLOBALS[index_value] . So here is the complete step by step tutorial for How to use $GLOBALS variable in php to access global variables.
android-project-download-code-button

How to use $GLOBALS variable in php to access global variables.

Code for globals-variables.php file.
 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>$GLOBALS variable in php to access global variables</title>
</head>

<body>

<?php

$a = 20; 
$b = 30;
 
function sum() 
{ 
 //ACCESSING VARIABLES USING GLOBALS
 $GLOBALS['c'] = $GLOBALS['a'] + $GLOBALS['b']; 
}
 
sum(); 

echo $c; 


?>

</body>
</html>
Screenshot:
use $GLOBALS variable in php to access global variables

Click here to download use $GLOBALS variable in php to access global variables project file with source code.

Comments

Popular posts from this blog

How to add image, header, and footer in PDF | PHP FPDF Tutorial Final

log in with facebook , paypal, php to pdf

How to make awesome stylish comment input box in PHP language for my website.