Example of dynamic variable usage in php

Source: Internet
Author: User
This article mainly introduces the usage of dynamic variables in php. examples show how to use dynamic variables in php. For more information, see

This article mainly introduces the usage of dynamic variables in php. examples show how to use dynamic variables in php. For more information, see

This example describes how to use dynamic variables in php. Share it with you 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 a loop statement to output all the values of each variable:

<? Phpfor ($ I = 1; $ I <= 8; $ I ++) {echo "$ my_pic _". $ I ;}?>

This output

<? Phpecho "$ my_pic _". $ I;?>

Certainly not.

Query php dynamic variable usage and change

<? Phpfor ($ I = 1; $ I <= 8; $ I ++) {$ my_pic_var = "$ my_pic ". $ I; // define the variable name echo $ my_pic_var; // obtain the variable name $ my_pic_var value $ my_pic_var; // The principle of PHP is as follows: $ my_pic_var = "$ my_pic_1" defines the variable value // $ my_pic_var is equal to the value of $ my_pic_1;}?>

I hope this article will help you with php programming.

,

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.