Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

${$var.'s_array'} can any one explain this?

Tags:

php

I am currently debugging a PHP OpenCart plugin and I have came across syntax I have never came across before.

I am interested in what this does and why it's used, and links to any documentation. The culprit is below:

${$variable.'s_array'}
like image 553
Adamski Avatar asked Mar 15 '23 04:03

Adamski


1 Answers

Variables in PHP can have variables in their declaration, like this:

e.g. try running this code-snippet:

$var = "dog_name";
$$var = "golden terrier";
echo $dog_name; //gives "golden terrier"

now to your case:

$variable = "random_";
${$variable.'s_array'} = "somecontent";
echo $random_s_array; //gives "somecontent"

this will give you dynamic variables.

Try this Sandbox-Example :)

PHP-Doc: http://php.net/manual/en/language.variables.variable.php (mentioned by versalle88)

like image 158
Tanuel Mategi Avatar answered Mar 24 '23 07:03

Tanuel Mategi