开发者社区 问答 正文

PHP:以递归方式将数组的赋值操作为键

现在,我只是使用以下简单查询和for循环填充数组:

foreach ($compatibility as $compElement) {

        $sql = "SELECT * FROM product WHERE ID = '$compElement';";

        $em = $this->getDoctrine()->getManager();
        $stmt = $em->getConnection()->prepare($sql);
        $stmt->execute();
        $thisElement = $stmt->fetchAll();

        $compArray[] = $thisElement;

    }

展开
收起
游客ufivfoddcd53c 2020-01-04 15:23:59 1161 分享 版权
1 条回答
写回答
取消 提交回答
  • 如果您不想更改填充数组的方式,可以执行以下操作:

    $result = call_user_func_array(
                   'array_merge_recursive',
                    $array
                );
    
    2020-01-04 15:24:17
    赞同 展开评论
问答分类:
问答地址: