- json_decode: documentation ( source)
- var_export: 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"
}
]';
$result = [];
foreach (json_decode($json, true) as $i => $row) {
foreach ($row as $id => $delimited) {
foreach (explode(';', $delimited) as $key => $value) {
$result[$i][$key][$id] = $value;
}
}
}
var_export($result);