Questions tagged [variable-variables]

Language feature of PHP: A variable variable takes the value of a variable and treats that as the name of a variable.

Language feature of PHP: A variable variable takes the value of a variable and treats that as the name of a variable.

171 questions
2
votes
2 answers

Variable variable for array

I have defined an array $array[1][1][test]="hello world". I would like to get this value by using variable variables. I have tried this, without success: $var1="array"; $var2="[1][1]"; $var3="['test']"; echo ${$var1}{$var2}{$var3}; Output is null.
Julian
  • 127
  • 1
  • 5
2
votes
1 answer

Variable variables doesn't work as expected and is creating an array

I'm using this line of code: $var{++$counter} = $results['row']; I've set this up with a goal of creating these variables: $var1 = row 1 $var2 = row 2 $var3 = row 3 Why is it created an array for $var ? Instead of just defining three variables?
KDJ
  • 309
  • 2
  • 14
2
votes
1 answer

Variable variables with arrays

I'm updating software that will import XML file of bank statement to invoicing software. One of the operations is through iteration looking for values in the structure of xml file (which the file itself is converted to associative array at this…
LukasS
  • 176
  • 7
2
votes
2 answers

Curly brace variable in array name, PHP

I know there are a lot of similar questions on here, and I think I've read them all. My problem is that I am attempting to loop through a list of arrays and grab one value from each. The arrays have been set up by a third party, and I don't have the…
2
votes
7 answers

Creating Variable Variables from MySQL Values

Is it possible to create a dynamic variable in PHP based on the value that comes from mysql database? I mean, say I have a field in mysql State When I read the value in php using row['State'] from the database and if I get a value like Alabama, I…
JPro
  • 6,292
  • 13
  • 57
  • 83
2
votes
4 answers

PHP: New variable from string concatenated with variable (variable-variables)

I am having a basic php problem that I haven't been able to resolve and I would also like to understand WHY! $upperValueCB = 10; $passNodeMatrixSource = 'CB'; $topValue= '$upperValue'.$passNodeMatrixSource; echo $topValue; OUTPUT…
EnglishAdam
  • 1,380
  • 1
  • 19
  • 42
2
votes
2 answers

Variable variables named after constants

I have the following class: class ClassFoo { const MY_CONSTANT = "bar"; function __construct() { $my_object = new stdClass; // This does not work $my_object->$ClassFoo::MY_CONSTANT = "foo"; } } I am trying to create a variable…
The Salt
  • 336
  • 5
  • 10
2
votes
1 answer

PHP - Node of a object - Variable name with "-" inside

As per discussion How to check if a string can be used as a variable name in PHP? the user TIM is giving there a good answer but still not solving my problem. I am doing the call exactly like that, but on production server they have magic quotes gpc…
andymnc
  • 103
  • 7
2
votes
4 answers

PHP variable variables in .NET

Does .NET natively support anything similar to PHP's variable variables? If not, how1 could such a feature be most easily implemented? 1 If you think variable variables are always bad, feel free to state your case but the main question is: how can…
Dinah
  • 52,922
  • 30
  • 133
  • 149
2
votes
2 answers

Variable variables and superglobals

I'm transitioning a huge PHP software from PHP4 to PHP5 and among the many (many) problems I'm facing, the biggest one so far seems to be that the previous programmer just banqueted over the register_globals feature, throwing every now and then some…
goffreder
  • 503
  • 3
  • 17
2
votes
1 answer

Python variable variables without eval?

Is there is a way to access variables using a variable string in python? For instance, I would like a neater way than using eval for the following: def toggleListButtons (self): buttons = ["flip", "remove", "removeAll", "delete", "deleteAll",…
Ben
  • 885
  • 1
  • 12
  • 25
2
votes
2 answers

variable variables, the key to my array

I found an example here that shows an example like this: Is it possible to modify it to work like…
penner
  • 2,707
  • 1
  • 37
  • 48
2
votes
4 answers

What is this loop using PHP $$ syntax doing?

I found this PHP code in an app I have to modify... $links = mysql_query($querystring); foreach (mysql_fetch_array($links) as $key=>$value) { $$key = $value; } I'm a bit stumped. Is it really iterating over the query results and copying the…
nedlud
  • 1,820
  • 4
  • 19
  • 33
1
vote
2 answers

Variable variables in JavaScript

according to my knowledge, this feature already exists in PHP. lets look at the following php code: $color = 'red'; $$color = 'dark'; description of the feature: Sometimes it is convenient to be able to have variable variable names. That is, a…
Sami Al-Subhi
  • 4,406
  • 9
  • 39
  • 66
1
vote
3 answers

Call defined constant from variable variable

I am trying to refer to a defined constant in a separate function. The errors I am getting refer to the variable not defined and the variable defined as a constant for each FOO and BAR. class Boo { public function runScare() { …
Matthew Sprankle
  • 1,626
  • 1
  • 19
  • 26