The examples in this article describe the dynamic variable usage in PHP. Share to everyone for your reference. The specific analysis is as follows:
Fixed variable defined:
$my _pic_1= $row ["pic_1"];
$my _pic_2= $row ["pic_2"];
$my _pic_3= $row ["Pic_3"];
$my _pic_4= $row ["Pic_4"];
$my _pic_5= $row ["Pic_5"];
$my _pic_6= $row ["Pic_6"];
$my _pic_7= $row ["pic_7"];
$my _pic_8= $row ["Pic_8"];
Here we use the Loop statement to lose all the values of each variable:
<?php for
($i =1 $i <=8; $i + +)
{
echo "$my _pic_". $i;
>
This output
<?php
echo "$my _pic_". $i
>
It's definitely not going to work.
Query PHP dynamic variable usage and change to
<?php
for ($i =1 $i <=8; $i + +) {
$my _pic_var= "$my _pic". $i;//define variable name
echo $ $my _pic_var;//Get variable name $my_ The value of Pic_var $ $my _pic_var;
The principle of PHP is this $my _pic_var= "$my _pic_1" defines the value
of the variable//$ $my _pic_var equal to the value of the read $my_pic_1;
}
? >
I hope this article will help you with your PHP program design.