Is there a way to store the text between the \begin and \end commands of a generic environment in an array?
A code that obviously doesn't work but shows what I mean is the following
\documentclass{memoir}
\usepackage{arrayjobx}
\newarray\entry
\newnvironment{mycenter}{\begin{center}\entry{0}={}{}\end{center}} % \entry{0} should be the text between \begin{mycenter} and \end{mycenter}
\begin{document}
\begin{mycenter}
This line is centered.
\end{mycenter}
\entry{0} % \entry{0} should be 'This line is centered'
\end{document}
Here I used the environment mycenter based on center, but the specific environment doesn't really matter, I just used it as an example.
Edit: I tried using the environ package as suggested by David Carlisle but I think I'm missing something here.
The edited code is
\documentclass{memoir}
\usepackage{arrayjobx, environ}
\newarray\entry
\NewEnviron{mycenter}{\entry(0)={\BODY}\begin{center}\BODY\end{center}}
\begin{document}
\begin{mycenter}
This line is centered.
\end{mycenter}
\entry(0)
\end{document}
which still doesn't compile. What am I doing wrong?

\begin{thm}and\end{thm}in an array and use a forloop to build the list once I have all the theorems. So in short, the values of the array will be texts. I'm aware thatthmtoolsoffers a\listoftheoremscommand, but that's now what I'm looking for. @DavidCarlisle could you show me how to use theenviron(ornewenviron) packages to do that? – noibe Feb 01 '19 at 14:45mycenterso you could define it with\NewEnvironinstead which would give you the content as\BODYbut it's rather different if you want to do similar with theorems which you are presumably defining already with a custom\newtheoremdeclaration. – David Carlisle Feb 01 '19 at 14:50\newtheorem{mythm}{some code}, then I can define a new environment\newenvironment{thm}{\begin{mythm}}{\end{mythm}}. – noibe Feb 01 '19 at 15:44