0

I have a large multidimentional array that I am looping through to change it's structure and theoretically this function will work accept the "variable array" part. And maybe that's not the right name for it as I have checked my resources and cannot come up with the right syntax for it but theoretically, I think I should be able to do it.

If you know what a variable variable is:

$variable = "blue";
$$variable = "red";

//what you get is
$blue = "red";

I am trying to do the same thing with an array:

$variable = "blue";
$$variable[] = "red";

//what I want is
$blue[0] = "red";

Does that make sense?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by R0bb0b
1

the syntax you are looking for is:

$variable = "blue";
${$variable}[] = "red";

//print array to see if it worked (did for me)
print_r(${$variable});
Votes + Comments
I think I looked for about 3 hrs for that, thx.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.