I search around for a bit but found nothing that did exactly what I'm after nor anything that really aided me in achieving what I'd like
I have data in this format:
array:4 [▼
"name" => array:2 [▼
0 => "ty"
1 => "word"
]
"phone" => array:2 [▼
0 => "2222222"
1 => "3333333"
]
"email" => array:2 [▼
0 => "[email protected]"
1 => "[email protected]"
]
"cnic" => array:2 [▼
0 => "567"
1 => "234"
]
]
I'd like to convert it all to this format:
[
{
"name" => "ty"
"phone" => "2222222"
"email" => "[email protected]"
"cnic" => "567"
},
{
"name" => "word"
"phone" => "3333333"
"email" => "[email protected]"
"cnic" => "234"
}
]
i tried:
foreach ($array as $key => $value) {
$x = count($array[0]["name"]);
for ($i=0; $i < $x; $i++) {
$newArray[] = [$value["name"][$i], $value["phone"][$i], $value["email"][$i] ,$value["cnic"][$i]];
}
}
but get no success