public function permissionStructure($Permissions,$Pid){ $child=[]; foreach ($Permissions as $key => $Permission) { if ($Permission['Pid']==$Pid) { $Permission['Child'] = $this->permissionStructure($Permissions,$Permission['ID']); $child[$Permission['Pid']][] = $Permission; } } return $child; }