Q:

PHP help - only need a simple explanation

Alright, I'm trying to understand how this PHP code works.
<?php
$test = "success";
$primary = "test";
$id = ${$primary};
echo $id;
?>

I know the output is "success" but I don't understand how it works.
What i understand so far:
test variable has the string "success",
 primary variable has the string "test",
 'id' variable has the string of the first variable in the list (the test variable),
 print the string in the 'id' variable.
I'm confused because i don't know what the primary variable is doing in the braces within the id variable.
A simple explanation would be appreciated.

A:

This is a concept called variable variables.
It means that at runtime, if multiple variable indicators $ are present, PHP will attempt to associate them in a cascading manner.
For example, take the following:
$a = "b";
$b = "c";
$c = "d";
echo $$$a;

PHP will systematically go through the echo statement to determine what the actual value is, as such:

$$$a is equivalent to $$("b") (because $a is "b")
...which is equivalent to $("c") (because $b is "c")
...which is finally equivalent to "d"

In your example, you're given a variable assignment to something that, in essence, is like ${$a}. In PHP, braces are used to isolate variables within strings, but can be used on their own to denote a variable explicitly, so ${$a} is exactly equivalent to $$a in this case.

A:

$id = ${$primary};

try to parse from right to left $primary = 'test'
so ${$primary} is now $test
so equation becomes  $id = $test;
$id = $test = success

Know more about variables variables on the link provided by other users

