Using Variable Substitution to Reference Another Variable in PHP and BASH Script


Not many programming languages support this kind of feature. We are not talking about substitution of the values in a string. Instead, we want to reference the variable using strings in a dynamic manner. In PHP, the following code illustrates itself.

$a = "1234";
$b = "a";
echo $$b;  //output 1234

This works because $b equals string a and $$b will just be deference as $a.

The same can be achieved using BASH.

bash-variable-substitution Using Variable Substitution to Reference Another Variable in PHP and BASH Script

bash-variable-substitution

Scripting languages are dynamic, loosely typed and do not require compilation, so it is likely that the languages supporting this feature are scripting.

–EOF (The Ultimate Computing & Technology Blog) —

160 words
Last Post: How to Add a Share Dropdown Menu after Each Post? (Javascript)
Next Post: HP Stream 7 Signature Edition Tablet Review

The Permanent URL is: Using Variable Substitution to Reference Another Variable in PHP and BASH Script (AMP Version)

Leave a Reply