Another opinion
Dynamic variables have utility, as can be seen in the following example.
In sending an long form instead of typing trocars times in the code, such as $nome = $_POT['nome']
By making use of dynamic variables the thing becomes very simplified, see how
foreach ( $_POST as $chave => $valor ) {
// $$chave cria as variáveis com os names dos elementos do formulário
$$chave = trim( strip_tags( $valor ) );
}
I'll cite another example of using these Variáveis variáveis, variáveis dinâmicas ou ainda variáveis criadas durante a execução no PHP
I have a hundred options as exemplified below:
echo ("<option value=\"youtube.php?n=s5&-----aaED7ZVkg0\"".$s5.">15/07/2016</option>\n");
echo ("<option value=\"youtube.php?n=s4&-----K_nny4LPEw\"".$s4.">15/07/2016</option>\n");
echo ("<option value=\"youtube.php?n=s3&-----u92sZyvhGw\"".$s3.">08/07/2016</option>\n");
echo ("<option value=\"youtube.php?n=s2&-----4BmVYRHypo\"".$s2.">08/07/2016</option>\n");
echo ("<option value=\"youtube.php?n=s1&-----_pM6kaYjc0\"".$s1.">08/07/2016</option>\n");
In this case you would like the user to click on an option and when the video is displayed, the option selected would be SELECTED
Notice that I am passing a parameter in the URL n=s1
n=s2
etc ....
How could you leave the selected option SELECTED
when directed to the video page?
An exhaustive and immense way would be through:
if ($_GET["n"]=="s1"){
$s1="" selected"";
}elseif($_GET["n"]=="s2"){
$s2="" selected"";
} ................
..................
elseif
a hundred times
Here is the use of the variable variable
$n = $_GET["n"];
$$n=" selected";
For $n=s1;
we will have $s1=" selected";
If it was useful to me? move the mouse in the yellow area below to find out
Very useful, I saved hundreds of else ifs
Variable variables, dynamic variables or even variables created during execution in PHP Credits
Regardless of the name you find out there in books or even the internet, it is a feature that allows us to create a variable through the contents of another variable.
To create a variable variable you use one variable to serve as an identifier for another variable that is created. For this we use the symbol $ twice, that is, we should use $$.