manipulating variables
Posted: Sat Jun 04, 2005 12:55 pm
If I initialize variable values:
$some_variable1 = 0;
$some_variable2 = 0;
... etc
And if I only have the variable name as a string "some_variable1" received as input from a different file, how do I then modify that variable without directly referring to that name by using the following:
$some_variable1++;
$some_variable1 = ... ;
I'm trying to modify variables based on the text strings I receive from a file. I don't want to make options for all possible variable names called because I want to receive any kind of variable name and if it doesn't exist, I want it to be created, then modified accordingly.
I'm basically trying to do something like this.
$some_variable1 = 0;
$string = "some_variable1"
"$some_variable1" = "$some_variable1" + 1;
print $some_variable; // outputs 1
though this is obviously incorrect code.
$some_variable1 = 0;
$some_variable2 = 0;
... etc
And if I only have the variable name as a string "some_variable1" received as input from a different file, how do I then modify that variable without directly referring to that name by using the following:
$some_variable1++;
$some_variable1 = ... ;
I'm trying to modify variables based on the text strings I receive from a file. I don't want to make options for all possible variable names called because I want to receive any kind of variable name and if it doesn't exist, I want it to be created, then modified accordingly.
I'm basically trying to do something like this.
$some_variable1 = 0;
$string = "some_variable1"
"$some_variable1" = "$some_variable1" + 1;
print $some_variable; // outputs 1
though this is obviously incorrect code.