PHP Snippet 1:
$arr = json_decode($s, true);
$new_arr = [];
foreach ($arr as $item) {
$parts1 = explode(';', $item[1]);
$parts2 = explode(';', $item[2]);
// $new_arr[] = array_map(null, $parts1, $parts2);
$tmp_arr = array_map(null, $parts1, $parts2);
$new_arr[] = array_map(
function($v) { return array_combine(["1","2"], $v); },
$tmp_arr
);
}
PHP Snippet 2:
$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 =[]; // empty array
}
var_dump($new);
PHP Snippet 3:
array(2) {
[0]=>
array(3) {
[0]=>
array(2) {
[1]=>
string(7) "tag_es1"
[2]=>
string(7) "tag_en1"
}
[1]=>
array(2) {
[1]=>
string(7) "tag_es2"
[2]=>
string(7) "tag_en2"
}
[2]=>
array(2) {
[1]=>
string(7) "tag_es3"
[2]=>
string(7) "tag_en3"
}
}
[1]=>
array(2) {
[0]=>
array(2) {
[1]=>
string(7) "tag_es1"
[2]=>
string(7) "tag_en1"
}
[1]=>
array(2) {
[1]=>
string(7) "tag_es2"
[2]=>
string(7) "tag_en2"
}
}
}
PHP Snippet 4:
$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);