I`ve got an associative array which looks like the following:
[
'one' => [
'two' => [
'three1' => 1,
'three2' => 'somestring',
]
] some more nodes...
I need to reverse it to the following:
'one.two.three1'=>1,
'one.two.three2'=>'somestring',
etc...
I can build the first string but for the second one it outputs only:
'three2'=>somestring'
but I need it to iterate from the beginning of the node. My code looks like the following:
$arr2 = array();
$finalarray = array();
function rewrapback($arr, &$arr2, &$finalarray, $level=0)
{
foreach($arr as $k=>$v)
{
$startnode = $k;
if(is_array($v))
{
$level=$level+1; //I suppose I need to do something with this but I don`t know what
array_push($arr2, $k);
rewrapback($v, $arr2, $finalarray,$level);
}else
{
array_push($arr2, $k);
$string = implode(',', $arr2);
$finalarray[$string]=$v;
$arr2 = array(); //reset the string
}
}
return $finalarray;
}
Any ideas on how to fix that? Thank you