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'}
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With