i need to assign a global variable value by passing it in a function, something like static variable i guess. Here is my code
<?php
//this is old value
$var = "Old Value";
//need to change the value of global variable
assignNewValue($var);
echo $var;
function assignNewValue($data) {
$data = "New value";
}
?>
After the execution the value of var need to be New Value. Thanks in advance.
assignNewValue()
. Instead, just do this:function assignNewValue(){ global $var; $var = "New value"; }
i need to assign a global variable
- no, you don't but you will. And your code will suck. Not now, but soon. By suck, I mean that you will shoot your own foot and lose time wondering what the hell just happened. Good luck.