Hi,
What is difference between $_Test[_Var1] V.S. $_Test_Var1?
Ex.:
$_Test[_Var1]= ...
$_Test[_Var2]= ...
$_Test[_Var3]= ...
V.S.
$_Test_Var1= ...
$_Test_Var2= ...
$_Test_Var3= ...
Thanks for answer ;).
Printable View
Hi,
What is difference between $_Test[_Var1] V.S. $_Test_Var1?
Ex.:
$_Test[_Var1]= ...
$_Test[_Var2]= ...
$_Test[_Var3]= ...
V.S.
$_Test_Var1= ...
$_Test_Var2= ...
$_Test_Var3= ...
Thanks for answer ;).
Apart from their names: $_Test[_Var1] is a variable that is an array with the index _Var1, as _VAR1 is not a string it should be declared prior as a constant. $_Test_Var1 is a variable rather than an array.
If _Var1 is not declared as a constant and strict mode is off then the interpreter will assume it means the string '_Var1' and generate a notice to this effect. If you have not already I strongly recommend enabling strict mode and using the full error reporting level (at least during development) in order to catch any ambiguous coding such as this.
Also, I would avoid using names that begin with an underscore since the underscore conventionally indicates a variable that is pre-populated by the interpreter.
Thanks both ;).