Answers for "use a global variable in a function php"

PHP
1

php set global variables from function

<?php 
function setGlobalVariable() {
    $GLOBALS['variable_name'] = "Some Value";
}
setGlobalVariable();
echo $variable_name;
// Outputs: Some Value
Posted by: Guest on September-10-2021
2

how make a variable global php

$a = 1;
$b = 2;
function Sum(){
    global $a, $b; // allows access to vars outside of function
    $b = $a + $b;
} 

Sum();
echo $b; // output is 3
Posted by: Guest on April-26-2021
0

php globals

$GLOBALS["foo"]
Posted by: Guest on October-21-2020

Code answers related to "use a global variable in a function php"

Browse Popular Code Answers by Language