值不保存在 foreach 循环之外

Value not saving outside foreach loop

我将我的代码从 PHP 5 更新为 PHP 7,我遇到了 foreach 循环的问题。我在这里查找了答案,但 none 正在运行。或者我不明白我哪里有问题

function getStructure($pid = 0, $expand = array(), $alevel = 0)
{
    $struct = array();
    if ( $alevel > $this->levelCount) $this->levelCount = (int)$alevel;

    $str = $this->dbStructure->getStructure($pid);
    foreach ($str as &$row)
    {
        if ($row["type"] == STRUCT_PAGE)
        {
            $row["editLink"]    = "editPage";
            $row["target"]        = "_self";
        }
        elseif ($row["type"] == STRUCT_MODULE)
        {
            $row["editLink"]    = "editModule";
            $row["target"]        = "_self";
        }
        elseif ($row["type"] == STRUCT_LINK)
        {
            $row["editLink"]    = "editLink";
            $row["target"]        = "_blank";
        }
        elseif ($row["type"] == STRUCT_CATALOG)
        {
            $row["editLink"]    = "editCatalog";
            $row["target"]        = "_self";
        }

        $row["childrens"] = $this->getStructure((int)$row["id"], $expand, $alevel+1);

        if ($row["type"] == STRUCT_CATALOG and isset($row["childrens"][0]["shortcut"]))
        {
            $row["shortcut"] = $row["childrens"][0]["shortcut"];
            $row["target"] = $row["childrens"][0]["type"] == STRUCT_LINK ? "_blank" : "_self";
        }

        $struct[] = $row;   
    }
    unset($row);
    return $struct;
}

$struct一直都是NULL,我需要多维数组

这段代码本身就很好。没有问题,只不需要&符号。问题出在不同的地方。抱歉垃圾邮件