php多表查询数据合并,避免foreach循环嵌套

$memberList = $member->getMemberList();
            $members = [];
            if (is_array($memberList)) {
                foreach ($memberList as $item) {
                    $members[$item["id"]] = $item["nickname"];
                }
            }

            foreach ($result as $item) {
                $item["member_name"] = array_key_exists($item["member_id"], $members) ? $members[$item["member_id"]] : "";
                $list[] = $item;
            }

 

posted @ 2018-07-26 20:30  pengcx  阅读(572)  评论(0编辑  收藏  举报