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.

1
2
3
$a = "1234";
$b = "a";
echo $$b;  //output 1234
$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 Shell php programming languages string technical tricks

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) —

GD Star Rating
loading...
177 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

Leave a Reply