首页 >后端开发 >php教程 >请问:PHP中,怎么获取提交的二维数组中某几列键值不为空的结果

请问:PHP中,怎么获取提交的二维数组中某几列键值不为空的结果

WBOY
WBOY原创
2016-06-13 12:03:26965浏览

请教:PHP中,如何获取提交的二维数组中某几列键值不为空的结果
所提交的结果如下:

Array<br />(<br />    [name] => Array<br />        (<br />            [0] => 地砖<br />            [1] => <br />            [2] => 空心砖<br />            [3] => 地砖<br />        )<br /><br />    [cunit] => Array<br />        (<br />            [0] => 块<br />            [1] => <br />            [2] => 块<br />            [3] => 块<br />        )<br /><br />    [unitprice] => Array<br />        (<br />            [0] => 35<br />            [1] => <br />            [2] => 3.5<br />            [3] => 35<br />        )<br /><br />    [pronum] => Array<br />        (<br />            [0] => 2<br />            [1] => <br />            [2] => 2<br />            [3] => <br />        )<br /><br />    [summoney] => Array<br />        (<br />            [0] => <br />            [1] => <br />            [2] => <br />            [3] => <br />        )<br /><br />)


<br />			$data=$_POST['sale'];<br />			//print_r($data);<br /><br />			foreach ($data as $k1 => $v1) {<br />				foreach ($v1 as $k2 => $v2) {<br />					$new_data[$k2][$k1] = $v2;<br />					$new_data[$k2]['username']='admin';<br />				}<br />			}<br /><br />

我想得到的最终结果是。name中数值不为空,且pronum数值不为空的结果。试了下if( $v2!=' ) 不对。特请教各位。谢谢了
------解决方案--------------------

<br>$arr=array<br>(<br>    'name' => array<br>        (<br>            0 =>'地砖',<br>            1 =>'',<br>            2 => '空心砖',<br>            3 => '地砖',<br>        ),<br>    'cunit' => array<br>        (<br>            0 => '块',<br>            1 => '',<br>            2 => '块',<br>            3 => '块'<br>        ),<br> <br>    'unitprice' => array<br>        (<br>            0 => 35,<br>            1 => '',<br>            2 => 3.5,<br>            3 => 35<br>        ),<br> <br>  'pronum' => array<br>       (<br>            0 => 2,<br>            1 => '',<br>            2 => 2,<br>            3 =>''<br>        ),<br>   'summoney' => array<br>        (<br>            0 =>'', <br>            1 =>'', <div class="clear">
                 
              
              
        
            </div>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn