$ {$ var.'s_array '} can someone explain this?

I am currently debugging a PHP opencart plugin and I came across a syntax that I have never come across.

Can someone explain what this does and why they used it, a link to any documentation, since my google-fu to search for something that I can not explain or understand is not very clear ;-). Criminal below:

${$variable.'s_array'}

I have no idea. Any help would be greatly appreciated.

Announcement

+4
source share
1 answer

Variables in PHP can have variables in their declaration, for example:

eg. try executing this piece of code:

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

now to your business:

$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 ( versalle88)

+7

Source: https://habr.com/ru/post/1615600/


All Articles