Example of passing array data in form, receiving by php script, and form Array

Source: Internet
Author: User

Example of passing array data in form, receiving by php script, and form Array

Using arrays to pass form data, you can save the business attribute relationships between data. For example, there are many Student, and every other Student has form information such as name, age, gender, and hobby. After submitting the form, you also need to process or save each student. In this way, you must establish an association relationship for these attribute forms of each student. One way is to add a special mark to the name of the attribute form for identification, however, passing the form through arrays makes the form data more structured.

Example:

<Input type = "hidden" name = "msginfo [name] []" value = "Zhang San"/> <input type = "hidden" name = "msginfo [phonenum] [] "value =" 111111111 "/> <input type =" hidden "name =" msginfo [name] [] "value =" "/> <input type =" hidden "name = "msginfo [phonenum] []" value = "222222222"/>

Php code:

<? Php $ msgInfos =$ _ POST ['msginfo']; $ phoneNums = $ msgInfos ['name']; // array (-=> JOHN, 1 => Lee IV) $ phoneNums = $ msgInfos ['phonenum']; // array (0 => 111111111,1 => 222222222)

Example 1

<? Phpif (isset ($ _ POST ['submit ']) {$ users =$ _ POST ['user']; foreach ($ users as $ key => $ val) {echo 'user', $ key, '=', $ val, '<br/>' ;}}?> <Form method = "post"> zhangsan <input type = "text" name = "user [zhangsan]" value = "0"/> <br/> lisi <input type = "text" name = "user [lisi]" value = "1"/> <br/> wangwu <input type = "text" name = "user [wangwu]" value = "2"/> <br/> zhaoliu <input type = "text" name = "user [zhaoliu]" value = "3"/> <br/> <input type = "submit" name = "submit" value = "submit"/> </form>

Example 2

<form method="post"><?for($i=0;$i<10;$i++){?><input type="checkbox" name="interests[]" value="<?=$i?>">test<?=$i?><br><?}?><input type="submit"></form><?php<code class="php keyword">if(isset($_POST)){ foreach($_POST as $key => $val){  if(is_array($val)){    foreach($val as $v2){    echo "$v2<br>";    }  } }}?></code>

The above example of passing array data in the form and receiving php scripts is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for our customer base.

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.