Home > Backend Development > PHP Tutorial > Dynamic variable usage examples in php, php variable usage examples_PHP tutorial

Dynamic variable usage examples in php, php variable usage examples_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:51:16
Original
856 people have browsed it

Examples of dynamic variable usage in php, php variable usage examples

The examples in this article describe the usage of dynamic variables in php. Share it with everyone for your reference. The specific analysis is as follows:

Fixed variables defined by

:

$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"];

Copy after login

Here we use a loop statement to output all the values ​​of each variable:

<&#63;php
for ($i=1;$i<=8;$i++)
{ 
 echo "$my_pic_".$i; 
}
&#63;> 

Copy after login

Output like this

<&#63;php
echo "$my_pic_".$i;
&#63;>
Copy after login

That’s definitely not possible.

Query the usage of php dynamic variables and change it to

<&#63;php
for ($i=1;$i<=8;$i++){
  $my_pic_var="$my_pic".$i; //定义变量名  
  echo $$my_pic_var; //获得变量名$my_pic_var的值$$my_pic_var; 
  //PHP的原理是这样的 $my_pic_var="$my_pic_1"定义变量值
  //$$my_pic_var等于读取$my_pic_1的值;  
}
&#63;>

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1014428.htmlTechArticleExamples of dynamic variable usage in php, php variable usage examples This article describes the usage of dynamic variables in php. Share it with everyone for your reference. The specific analysis is as follows: Fixed variables defined:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template