请问:PHP中,怎么获取提交的二维数组中某几列键值不为空的结果
程序员文章站
2022-05-20 12:28:37
...
请教:PHP中,如何获取提交的二维数组中某几列键值不为空的结果
所提交的结果如下:
我想得到的最终结果是。name中数值不为空,且pronum数值不为空的结果。试了下if( $v2!=' ) 不对。特请教各位。谢谢了
------解决方案--------------------
所提交的结果如下:
Array
(
[name] => Array
(
[0] => 地砖
[1] =>
[2] => 空心砖
[3] => 地砖
)
[cunit] => Array
(
[0] => 块
[1] =>
[2] => 块
[3] => 块
)
[unitprice] => Array
(
[0] => 35
[1] =>
[2] => 3.5
[3] => 35
)
[pronum] => Array
(
[0] => 2
[1] =>
[2] => 2
[3] =>
)
[summoney] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
)
$data=$_POST['sale'];
//print_r($data);
foreach ($data as $k1 => $v1) {
foreach ($v1 as $k2 => $v2) {
$new_data[$k2][$k1] = $v2;
$new_data[$k2]['username']='admin';
}
}
我想得到的最终结果是。name中数值不为空,且pronum数值不为空的结果。试了下if( $v2!=' ) 不对。特请教各位。谢谢了
------解决方案--------------------
$arr=array
(
'name' => array
(
0 =>'地砖',
1 =>'',
2 => '空心砖',
3 => '地砖',
),
'cunit' => array
(
0 => '块',
1 => '',
2 => '块',
3 => '块'
),
'unitprice' => array
(
0 => 35,
1 => '',
2 => 3.5,
3 => 35
),
'pronum' => array
(
0 => 2,
1 => '',
2 => 2,
3 =>''
),
'summoney' => array
(
0 =>'',
1 =>'',相关文章
相关视频
上一篇: MySQL 存储过程的基本用法介绍