Php uses the key value of the post array to create a variable with the same name and assign a value

Source: Internet
Author: User
This article mainly introduces how php uses the key value of the post array to create and assign values to variables of the same name. It involves php Array Operations and is very useful. For more information, see

This article mainly introduces how php uses the key value of the post array to create and assign values to variables of the same name. It involves php Array Operations and is very useful. For more information, see

This example describes how php creates and assigns values to variables of the same name using the key value of the post array. Share it with you for your reference. The details are as follows:

This code automatically creates a variable of the same name based on the key value of the post array. This function is very convenient to use and does not need to declare variables in advance.

<? Php $ expected = array ('username', 'age', 'city', 'street'); foreach ($ expected as $ key) {if (! Empty ($ _ POST [$ key]) {$ {key }== _ POST [$ key] ;}else {$ {key }= NULL ;}}?>

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.