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 356 views
1 answer 232 views
3 answers 213 views
213 views asked Oct 17, 2015 by avibootz
3 answers 323 views
1 answer 148 views
...