map(function ($hd) use ($bdPage, $toName, $fromName, $pageName) { $filterPage = collect($bdPage)->filter(function ($bd) use ($hd, $toName, $fromName) { return $hd[$fromName] === (int)$bd[$toName]; })->values()->toArray(); return array_merge($hd, [$pageName => $filterPage]); })->toArray(); } }