Example of dynamic variable usage in PHP, PHP variable usage example
The example in this article describes the usage of dynamic variables in PHP. Share to everyone for your reference. The specific analysis is as follows:
Fixed variables 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 loop statements to lose the value of each variable:
<?phpfor ($i =1; $i <=8; $i + +) {
This output
<?phpecho "$my _pic_". $i;? >
It's definitely not going to work.
Query PHP dynamic variable usage and change to
<?phpfor ($i =1; $i <=8; $i + +) { $my _pic_var= "$my _pic". $i;//define variable name echo $ $my _pic_var;//Get variable name $my_pic_ The value of 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 equals the value of the read $my_pic_1; }? >
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1014428.html www.bkjia.com true http://www.bkjia.com/PHPjc/1014428.html techarticle Examples of dynamic variable usages in PHP, examples of PHP variable usage This article describes the use of dynamic variables in PHP. Share to everyone for your reference. The specific analysis is as follows: Defined fixed variables: ...