Another opinion
Dynamic variables have a use yes as can be seen in the following example.
In sending a extensive form instead of typing hundreds times in the code, for example, $nome = $_POT['nome']
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 will quote another example of the use of 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 I would like the user to click on an option and when the video is displayed, the option selected would be SELECTED
Note that I am passing a parameter in the URL n=s1
n=s2
etc.....
How could one leave the option selected 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 comes the variable usage
$n = $_GET["n"];
$$n=" selected";
To $n=s1;
we shall have $s1=" selected";
Did I help you? Hover your mouse in the yellowish area below to find out
Very useful, saved hundreds of ifs
Variables, dynamic variables or variables created during PHP execution Credits
Regardless of the name you find around in books or even on the Internet, it is a resource that allows us to create a variable through the content of another variable.
To create a variable you use one variable to act as an identifier for another that is created. For this we use twice the $symbol, that is, we must use $$.
It reminds me a lot of the pointers of the C language, when you want to access the address of the address of a variable
***v;
– gato
Related: https://answall.com/questions/171153/variav%C3%A9l-Vari%C3%A1vel-em-php
– bfavaretto
And as Diego said downstairs: In practice, don’t use this.
– bfavaretto
@bfavaretto I took the liberty of adding your link in the reply, I found it interesting ok?
– Diego
Okay @Diego, no problem.
– bfavaretto