php - change structure of array -
this nationality of commune.
i have array multi form post
array ( [pid] => array ( ) [commune] => array ( [0] => 64 [1] => 64 [2] => 64 [3] => 64 e.t.c ... ) [nationality] => array ( [0] => af [1] => al [2] => de [3] => e.t.c ... ) [female] => array ( [0] => 4 [1] => 0 [2] => 119 [3] => 13 e.t.c ... ) [male] => array ( [0] => 2 [1] => 0 [2] => 102 [3] => 16 e.t.c ... ) [send] => array ( ) )
and need change structure:
array ( [0] => array ( [commune] => 64 [nationality] => af [female] => 4 [male] => 2 ) [1] => array ( [commune] => 64 [nationality] => al [female] => 0 [male] => 0 ) [2] => array ( [commune] => 64 [nationality] => de [female] => 119 [male] => 102 ) [3] => array ( [commune] => 64 [nationality] => [female] => 13 [male] => 16 ) )
e.t.c ...
if in array [1] [female] = 0 amd [male] = 0 need delete array [1]
after need insert value [commune], [nationality], [female] , [male] in mysqli
name of columns un table same commune,nationality,female,male
marc
here code:
$ar_val = array('pid' => array(), 'commune' => array(64,64,64,64),'nationality' => array('af','al','de','us'),'female' => array(4,0,119,13),'male' => array(2,0,102,16), 'send' => array()); foreach($ar_val $ar_key=>$ar_val){ $i = 0; foreach($ar_val $arry_val){ $output[$i][$ar_key] = $arry_val; $i++; } } print_r($output);
$ar_val
main array in having form values.
you can try test code well. working me.
above code change below array output:
array ( [commune] => array ( [0] => 64 [1] => 64 [2] => 64 [3] => 64 ) [nationality] => array ( [0] => af [1] => al [2] => de [3] => ) [female] => array ( [0] => 4 [1] => 0 [2] => 119 [3] => 13 ) [male] => array ( [0] => 2 [1] => 0 [2] => 102 [3] => 16 ) )
to below array:
array ( [0] => array ( [commune] => 64 [nationality] => af [female] => 4 [male] => 2 ) [1] => array ( [commune] => 64 [nationality] => al [female] => 0 [male] => 0 ) [2] => array ( [commune] => 64 [nationality] => de [female] => 119 [male] => 102 ) [3] => array ( [commune] => 64 [nationality] => [female] => 13 [male] => 16 ) )
Comments
Post a Comment