时间:2021-07-01 10:21:17 帮助过:24人阅读
品名: 型号: 规格: 数量: 单价: 总价: |
品名: 型号: 规格: 数量: 单价: 总价: |
array 'pinming' => array 0 => string '123' (length=3) 1 => string '123' (length=3) 'xinghao' => array 0 => string '123' (length=3) 1 => string '123' (length=3) 'guige' => array 0 => string '123' (length=3) 1 => string '123' (length=3) 'shuliang' => array 0 => string '123' (length=3) 1 => string '123' (length=3) 'danjia' => array 0 => string '123' (length=3) 1 => string '123' (length=3) 'zongjia' => array 0 => string '12312' (length=5) 1 => string '123' (length=3)
array( //第一条 array( 'pinming' => 'xxx' 'guige' => 'xxx' //....其他字段 ) //第二条 array( 'pingming' => 'xxx' 'guige' => 'xxx' //其他字段 ) //第N条 array())
不就一个行列交换么?
class squareArray{ public function swapRowCol($inArr) { $mit = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC); foreach($inArr as $key => $value) { $temArr = new ArrayIterator($value); $mit->attachIterator($temArr, $key); } $arr = array(); foreach($mit as $item) array_push($arr,$item); if (isset($inArr[0])) $arr = array_combine(array_keys($inArr[0]),$arr); return $arr; } public function swapRowColWithKey($inArr) { foreach($inArr as $k1=>$v1) foreach($v1 as $k2=>$v2) $arr[$k2][$k1] = $v2; return $arr; }...
本来你的输入网页就应该设计成一行(一个td)用一组变量名,那不就简单了
foreach($_POST as $name=>$item) { if(is_array($item)) { foreach($item as $key=>$value) { $res[$kek][$name] = $value; } }}$res 就是你要的结果
$fields=array('pinming','guige','xinghao','shuliang','danjia','zongjia');$data=array();foreach($_POST['pinming'] as $key=>$vo){ foreach($fields as $item){ $data[$key][$item]=$_POST[$key][$item]; }}//$data is the result
foreach($_POST as $name=>$item) { if(is_array($item)) { foreach($item as $key=>$value) { $res[$kek][$name] = $value; } }}$res 就是你要的结果
先完成行列转换,然后删去全空的项目
foreach($res as $i=>$item) { if(trim(join('', $item)) == '') unset($res[$i]);}
这种提交没有必要搞这么复杂
只要你确定1点就可以简单化,就是哪一项是必填项,也就是说不能为空的
这里我假设品名不能为空,那么程序之需要这样就可以
foreach($pinming as $key=>$val) { $uparr=array(); if(trim($val)!='') { $uparr['pinming']=$val; $uparr['xinghao']=$pinming[$key]; $uparr['guige']=$guige[$key]; $uparr['shuliang']=$shuliang[$key]; $uparr['danjia']=$danjia[$key]; $uparr['zongjia']=$zongjia[$key]; //这里加插入数据库语句 }}
foreach($_POST as $name=>$item) { if(is_array($item)) { foreach($item as $key=>$value) { $res[$kek][$name] = $value; } }}$res 就是你要的结果
foreach($_POST as $name=>$item) { if(is_array($item)) { foreach($item as $key=>$value) { $res[$kek][$name] = $value; } }}$res 就是你要的结果
foreach($_POST as $name=>$item) { if(is_array($item)) { foreach($item as $key=>$value) { $res[$kek][$name] = $value; } }}$res 就是你要的结果
也就是
$newarr=array();foreach($pinming as $key=>$val) { $uparr=array(); if(trim($val)!='') { $uparr['pinming']=$val; $uparr['xinghao']=$pinming[$key]; $uparr['guige']=$guige[$key]; $uparr['shuliang']=$shuliang[$key]; $uparr['danjia']=$danjia[$key]; $uparr['zongjia']=$zongjia[$key]; $newarr[]=$uparr; }}