#Convert a HTML input 2-dimensional array into an array of keys-values
We get this JSON input:
{
"number":[
"1241",
"1241"
],
"client_instructions":[
"Test",
"Test 2"
]
}
We need this output:
[
{
"number" : "1241",
"client_instructions" : "Test"
},
{
"number" : "1241",
"client_instructions" : "Test 2"
}
]
I came up with this
$output = [];
$keys = array_keys($array);
$i = 0;
do{
$o = [];
foreach($keys as $k){
$o[$k] = $array[$k][$i];
}
$output[] = $o;
$i++;
} while($i < count($array[$keys[0]]));
Could this be done better?