Example of dynamic variable usage in PHP, PHP variable usage example _php tutorial

Source: Internet
Author: User

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: ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.