This JSON represents an Employee -> Supervisor relationship that looks like this:
{
"Pete": "Nick",
"Barbara": "Nick",
"Nick": "Sophie",
"Sophie": "Jonas"
}
In this case, Nick is a supervisor of Pete and Barbara, Sophie supervises Nick.
i want to make it hierarchy as this
{“Jonas" : [
{“Sophie": [
{“Nick" : [
{"Pete": []},
{"Barbara": []}
]}
]}
]}
I tried to make an array for the keys and values ( even index for value and odd for keys )
$i =0;
$arr[] = array();
foreach ($files as $key => $f)
{
$arr[$i] = $f;
$i++;
$arr[$i] = $key;
$i++;
}
the iterate to find the root that have even index and not duplicate
$i++;
for($x=0;$x<=6;$x+2){
for($z=1;$z<7;$z+2){
if($arr[$x] != $arr[$z]){
#som code
}
}
}
then find the children which is the next of it, but works only with the root
can some one help