Confused about why these two integrals are equal (Measure Theory) I don't understand the second part of the proof to this theorem:

The author writes the following:

I can't really understand any of the explanation. The first sentence, perhaps; for example, in the case $\chi_E = g$ I can see why the integral on the RHS of (2) is equal to $\varphi(E)$ since, in this case, $\int_X gf \ d\mu = \int_E f \ d\mu = \varphi(E)$. But for the LHS of (2) I don't think I am allowed to actually write the following: $$\int_X g \ d\mu = \int_E \ d\mu = \int_E \ d(\int_E f \ d\mu) = \int_E f \ d\mu = \varphi(E)$$ I don't even think I can legitimately do that based on my current knowledge of a Lebesgue integral. So even the first part is confusing me.
In addition, even if I understood this equality for the case $g = \chi_E$ I can't quite grasp how the final sentence of the proof shows how to generalise it.
I appreciate any assistance. Thank you very much!
 A: By the very definition of the integral with respect to the measure $\varphi$, we have
$$\varphi(E)= \int_X \chi_E \, d\varphi. \tag{3}$$
On the other hand, $(1)$ shows
$$\varphi(E) = \int_E f \, d\mu = \int_X \chi_E \cdot f \, d\mu. \tag{4}$$
Combining $(3)$ and $(4)$ we get
$$\int_X \chi_E \, d\varphi = \int_X \chi_E \cdot f \, d\mu$$
which is $(2)$ for the indicator function $g = \chi_E$. By the linearity of the integral, $(2)$ extends to simple functions.
Now if $g$ is a measurable non-negative function, then there exists a sequence of simple functions $(g_n)_{n \in \mathbb{N}}$ such that $g_n \geq 0$ and $g_n \uparrow g$ (i.e. $g_1(x) \leq g_2(x) \leq \ldots$ and $g(x) = \sup_n g_n(x)$ for all $x \in X$). Since we already know that $(2)$ holds for simple functions, we have
$$\int_X g_n \, d\varphi = \int_X g_n \cdot f \, d\mu \tag{5}$$
for all $n \in \mathbb{N}$. Applying the monotone convergence theorem (MCT), we find
$$\begin{align*} \int_X g \, d\varphi &\stackrel{\text{MCT}}{=} \sup_{n \in \mathbb{N}} \int_X g_n \, d\varphi \\ &\stackrel{(5)}{=} \sup_{n \in \mathbb{N}} \int_X g_n \cdot f \, d\mu \\ &\stackrel{\text{MCT}}{=} \int_X g \cdot f \, d\mu. \end{align*}$$
Here, we have used in the last step that $f \cdot g_n \uparrow f \cdot g$ since $f$ is, by assumption, non-negative.
A: Let's try specific examples, which we can visualize by sketching: 
$$
X = [0, 1], 
$$
$$
dm_{L} = \mbox{the Lebesgue measure on ${\bf R}$},
$$
$$
f(x) = x,
$$
so
$$
\phi(E) = \int_{E} x \; dm_{L}(x),
$$
(thus, for example, for $E = [a, b] \subset [0, 1]$, we have $\phi(E) = \int_{a}^{b} x \; dx$ in the Riemannian sense), and let's first see if the equality you are studying holds when $g(x)$ is piecewise constant (so for now we'll call it $g_{pwc}$).
What is $\int_{X} g_{pwc} \; d\phi$?  Well, on every interval $E = [a, b] \subset X$ on which $g_{pwc}$ is constant (and has value we will denote by $c_{E}$) we have:
$$
\begin{array}{llll}
\int_{E} g_{pwc} \; d\phi & = & c_{E} \int_{E} d\phi & \mbox{(because $g_{pwc} = c_{E}$ on $E$)}\\
& = & c_{E} \; \phi(E) & \mbox{(by the definition of $d \phi$)}\\
& = & c_{E} \int_{E} f \; dm_{L} & \mbox{(by the definition of $\phi$)}\\
& = & \int_{E} c_{E} \; f \; dm_{L} & \mbox{(by the linearity of the Lebesgue integral)}\\
& = & \int_{E} g_{pwc} \, f \; dm_{L} &  \mbox{(because $g_{pwc} = c_{E}$ on $E$).}\\
\end{array}
$$
This computation still holds for arbitrary $X, \phi, f, \mu$.  I used $[0, 1]$ only so we could carry out the actual computation.
Now, for arbitrary $g$, we approximate it by a sequence of $g_{pwc}$ and, taking the limit, get the desired result.
