php - I have data in array format, how could i take each value from an array and built a new array -


i have data in array format this:-

array (     [itemid] => array         (             [0] => 1001             [1] => 1002         )     [itemname] => array         (             [0] => sample item 1             [1] => sample item 2         )     [itemdesc] => array         (             [0] => item specifications             [1] => item warranty         )     [itemcode] => array         (             [0] => gl2113             [1] => sp88293         )     [itemqty] => array         (             [0] => 1             [1] => 5         )      [itemtype] => array         (             [0] => electronic             [1] => computer         ) ) 

how convert below format:-

array(     [0]=>array(         [itemid]    =>1001,         [itemname]  =>sample item one,         [itemdesc]  =>item specifications,         [itemcode]  =>gl2113,         [itemqty]   =>1,         [itemtype]  =>electronic         )     [1]=>array(         [itemid]    =>1002,         [itemname]  =>sample item two,         [itemdesc]  =>item warranty,         [itemcode]  =>sp88293,         [itemqty]   =>5,         [itemtype]  =>computer         ) ) 

it's sad question's format, it's solution you

<?php  $a = [     'itemid'   => [          '0' => '1001',          '1' => '2002'      ],     'itemname' => [          '0' => 'dan',          '1' => 'bob'      ],     'itemdesc' => [         '0' => 'foo',         '1' => 'bar'     ]     ];  $b = [];  foreach ($a $aa => $v ) {     foreach ($v $kk => $vv) {         $b[$kk][$aa] = $vv;     } }  var_dump($b);  ?> 

output:

array(2) {   [0]=>   array(3) {     ["itemid"]=>     string(4) "1001"     ["itemname"]=>     string(3) "dan"     ["itemdesc"]=>     string(3) "foo"   }   [1]=>   array(3) {     ["itemid"]=>     string(4) "2002"     ["itemname"]=>     string(3) "bob"     ["itemdesc"]=>     string(3) "bar"   } } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -