In PHP, how to obtain the submitted results of a few columns of the two-dimensional array whose key values are not empty is as follows:
Array ([name] => Array ([0] => floor tile [1] => [2] => hollow brick [3] => floor tile) [cunit] => Array ([0] => block [1] => [2] => block [3] => block) [unitprice] = & gt; Array ([0] = & gt; 35 [1] = & gt; [2] = & gt; 3.5 [3] = & gt; 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';}}
The final result I want is. Result where the value of name is not empty and the value of pronum is not empty. Tried if ($ v2! = ') Incorrect. I would like to ask you. Thank you.
Reply to discussion (solution)
$ Arr = array ('name' => array (0 => 'Tile ', 1 => '', 2 => 'hollow block ', 3 => 'barri',), 'cunit '=> array (0 => 'block', 1 => '', 2 => 'block ', 3 => 'block'), 'unitprice' => array (0 => 35, 1 => '', 2 => 3.5, 3 => 35 ), 'pronum' => array (0 => 2, 1 => '', 2 => 2, 3 => ''), 'summoney' => array (0 => '', 1 =>'', 2 => '', 3 =>''); $ new_data = array (); foreach ($ arr as $ k => $ v) {if ($ k = 'name' | $ k = 'pronum') {foreach ($ v as $ new K => $ newv) {if ($ newv! = '') {$ New_data [$ k] [] = $ newv ;}}} print_r ($ new_data ); [code = php] Array ([name] => Array ([0] => floor tile [1] => hollow brick [2] => floor tile) [pronum] => Array ([0] => 2 [1] => 2 ))
[/Code]
In fact, this is easy for subsequent processing.
Array ([0] => Array ([name] => tile [cunit] => block [unitprice] => 35 [pronum] => 2 [summoney] =>) [2] => Array ([name] => hollow brick [cunit] => block [unitprice] => 3.5 [pronum] => 2 [summoney] => ))
$k = array_keys($data);foreach(call_user_func_array('array_map', array_merge(array(null), $data)) as $i=>$r) { $r = array_combine($k, $r); if($r['name'] && $r['pronum']) $res[$i] = $r;}
Thank you for the xuzuning moderator. Thanks to luo19880415.