setting Global variable not working in Symfony : I could not access `$result` outside the foreach loop .when I use ` dump($results);` inside the loop I'm getting result but when I'm using ` dump($results);` outside the loop result is empty.

     $results=array();
        foreach ( $menu as $menus)
            {
                $mid = $menus->getId();
                $em = $this->getDoctrine()->getManager();
                $connection = $em->getConnection();

                $statement = $connection->prepare("SELECT s.subtitle,m.* FROM submenu as s,menu as m where s.menu_id=m.id and m.id=:data");
                $statement->bindValue('data', $mid);
                $statement->execute();
                $results = $statement->fetchAll();


            }
        dump($results)