I'm trying to store some values in one array, where each element has its child element.
Please find the code:
$children = $user->relations()->wherePlanId($selectplan)->get();
foreach($children as $ch)
{
$child[] = $ch->pivot->child;
$subuser = User::find($ch->pivot->child);
if($subuser){
$subchildren = $subuser->relations()->wherePlanId($selectplan)->get();
foreach($subchildren as $subchild)
{
$subchildid[] = $subchild->pivot->child;
}
}
else
{
$subchildid[] = NULL;
}
}
I want to store something like child['parent_element']['child_element']
i.e expected array format
child[1][2]
child[1][3]
child[1][4]
child[1][5]
child[2][6]
child[2][7]
.
.
child[3][12]
Help me out. Thanks