- var_dump: documentation ( source)
- array_combine: documentation ( source)
- json_decode: documentation ( source)
- array_column: documentation ( source)
- explode: documentation ( source)
<?php
$json = '[
{
"1": "tag_es1;tag_es2;tag_es3",
"2": "tag_en1;tag_en2;tag_en3"
},
{
"1": "tag_es1;tag_es2",
"2": "tag_en1;tag_en2"
}
]';
$arr = json_decode($json, true);
foreach($arr as $key1 => $sub){
foreach($sub as $item){
$temp[] = explode(";", $item);
}
foreach($temp[0] as $key2 => $val){
$new[$key1][]= array_combine([1,2],array_column($temp, $key2));
}
$temp =[];
}
Var_dump($new);