I made two recursive functions to implode and explode.
The result of multi_explode
may not work as expected (the values are all stored at the same dimension level).
function multi_implode(array $glues, array $array){
$out = "";
$g = array_shift($glues);
$c = count($array);
$i = 0;
foreach ($array as $val){
if (is_array($val)){
$out .= multi_implode($glues,$val);
} else {
$out .= (string)$val;
}
$i++;
if ($i<$c){
$out .= $g;
}
}
return $out;
}
function multi_explode(array $delimiter,$string){
$d = array_shift($delimiter);
if ($d!=NULL){
$tmp = explode($d,$string);
foreach ($tmp as $key => $o){
$out[$key] = multi_explode($delimiter,$o);
}
} else {
return $string;
}
return $out;
}
To use them:
echo $s = multi_implode(
array(';',',','-'),
array(
'a',
array(10),
array(10,20),
array(
10,
array('s','t'),
array('z','g')
)
)
);
$a= multi_explode(array(';',',','-'),$s);
var_export($a);