How to change a global variable from inside a function in PHP

1 Answer

0 votes
$x = 46;

function modify_global() {
  global $x;
  
  $x = 901;
}

echo $x . "\n";

modify_global();

echo $x; 

 
 
 
 
/*
run:
 
46
901

*/
 

 



answered Dec 3, 2023 by avibootz

Related questions

4 answers 368 views
1 answer 241 views
3 answers 230 views
230 views asked Oct 17, 2015 by avibootz
3 answers 342 views
1 answer 160 views
...