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.