When you write \begin{env1}...\end{env1} roughly what happens is that LaTeX starts a "group" and then inserts commands \env1...\endenv1. So to do this it is enough to make the commands \foo and \endfoo execute \env1 and \endenv1 etc, which is easy to do using the \letcs command from the etoolbox package. In more detail,
\documentclass{article}
\usepackage{etoolbox}
\usepackage{verbatim}
\newenvironment{env1}{Environment 1\csuse{verbatim*}}{\csuse{endverbatim*}}
\newenvironment{env2}{Environment 2\verbatim}{\endverbatim}
\newcommand\SetFoo[1]{\letcs{\foo}{env#1}\letcs{\endfoo}{endenv#1}}
\begin{document}
\SetFoo{1}
\begin{foo}
My little environment
\end{foo}
\SetFoo{2}
\begin{foo}
My little environment
\end{foo}
\end{document}
produces the output

As in the MWE, you can use the command \SetFoo to change the meaning of the foo environment as many times as you like in the document, including just once in the preamble. In effect, the \SetFoo{?} macro defines the foo environment so it needs to be "called" before the first foo environment.
In the code above I have shown two different example uses of verbatim environments. This might fit your use-case but without knowing more about what you are trying to do this is not guaranteed - this is why it is always better to include as much detail as possible in a minimal working example as part of any question.
Side note As a general rule, LaTeX commands should not have numbers in them but, as shown, this works OK for environments although such usage may offend purists.
\newenvironmentmacro, it will be easier to get help (we will just have to correct your macro). I am not a macro wizzard, but I would also set a new counter (newcounter) flagenv. AFAIK,flagenv=1is not the proper way to declare a variable in TeX. You could set your flagenv to 1 and use conditionnals depending on the fact that your counter is odd or even. – sztruks Nov 26 '18 at 07:30env1andenv2are derived fromVerbatimis crucial. Can you please give a short example of how you define them? – egreg Nov 26 '18 at 08:57