I have data in array format like this:-
Array
(
[itemId] => Array
(
[0] => 1001
[1] => 1002
)
[itemName] => Array
(
[0] => Sample Item one
[1] => Sample Item two
)
[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 to convert that into 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 so sad about you question's format, but it's the solution for you
<?php
$a = [
'itemId' => [
'0' => '1001',
'1' => '2002'
],
'itemName' => [
'0' => 'Dan',
'1' => 'Bob'
],
'itemDesc' => [
'0' => 'Foo',
'1' => 'Bar'
]
];
$b = [];
foreach ($a as $aa => $v ) {
foreach ($v as $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"
}
}