Home  >  Article  >  Backend Development  >  PHP分析POST重复值

PHP分析POST重复值

WBOY
WBOYOriginal
2016-06-23 13:56:061046browse

客户端HTML

<form action="new.php" method="post">	<input name="part" type="text" />	<input name="transysno" type="text" />	<input name="tranlineid" type="text" />        <input name="count" type="text" />	<input name="part" type="text" />	<input name="transysno" type="text" />	<input name="tranlineid" type="text" />        <input name="count" type="text" />	<input type="submit" name="post" value="提交" /></form>


怎么在PHP服务端判断 两组part,transysno,tranlineid 是否相同 ,如果相同则获取相同count的和


回复讨论(解决方案)

php 要求传入的同名变量写作数组形式
所以你的表单中的两组同名控件,只会有一组被 php 接收到

php 要求传入的同名变量写作数组形式
所以你的表单中的两组同名控件,只会有一组被 php 接收到



写成数组 之后 怎么能 分析出 四个变量中三个变量的值是否相同 然后判断是否合并他们的count呢

提交后 print_r($_POST); 就知道该怎么做了

客户端html

<form action="news.php" method="post">    <input name="part[]" type="text" />    <input name="transysno[]" type="text" />    <input name="tranlineid[]" type="text" />        <input name="count[]" type="text" />     <input name="part[]" type="text" />    <input name="transysno[]" type="text" />    <input name="tranlineid[]" type="text" />        <input name="count[]" type="text" />    <input type="submit" name="post" value="提交" /></form>


news.php
if($_POST['part'][0]==$_POST['part'][1] && $_POST['transysno'][0]==$_POST['transysno'][1] && $_POST['tranlineid'][0]==$_POST['tranlineid'][1]){    echo ($_POST['count'][0] + $_POST['count'][1]);}else{    echo 'part,transysno,tranlineid not match';}

结贴 参阅了 http://bbs.csdn.net/topics/360243533

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn