you should assign $request->request->get('elements', array()) outside the loop to avoid multiple call