what is “$$” in PHP
It’s evil is what it is. That will take the value that’s in $textVarName and use that as a variable name. For example: $foo = ‘hello’; $hello = ‘The Output’; echo $$foo; // displays “The Output”
It’s evil is what it is. That will take the value that’s in $textVarName and use that as a variable name. For example: $foo = ‘hello’; $hello = ‘The Output’; echo $$foo; // displays “The Output”
Python doesn’t have a feature that’s directly equivalent to PHP’s “variable variables”. To get a “variable variable”‘s value (or the value of any other expression) you can use the eval function. foo = “Hello World” print eval(“foo”) However, this can’t be used in an import statement. It is possible to use the __import__ function to … Read more
Its purpose, I guess, is to allow novice programmers to dynamically change data without using “complicated stuff” like composite types (arrays and objects). I never use them.
In most cases like this, an ordinary dictionary will do the job just fine. >>> get_ext = {‘text’: [‘txt’, ‘doc’], … ‘audio’: [‘mp3’, ‘wav’], … ‘video’: [‘mp4’, ‘mkv’] … } >>> >>> get_ext[‘video’] [‘mp4’, ‘mkv’] If you really want or need a function (for which there can be valid reasons) you have a couple of … Read more
tl;dr: Don’t use eval! There is no single solution for this. It is possible to access some global variables dynamically via window, but that doesn’t work for variables local to a function. Global variables that do not become a property of window are variables defined with let and const, and classes. There is almost always … Read more
You can use dictionaries to accomplish this. Dictionaries are stores of keys and values. >>> dct = {‘x’: 1, ‘y’: 2, ‘z’: 3} >>> dct {‘y’: 2, ‘x’: 1, ‘z’: 3} >>> dct[“y”] 2 You can use variable key names to achieve the effect of variable variables without the security risk. >>> x = “spam” … Read more