How to prove the function is a constant

Let $f\in C[0,1]$ be such that $\forall \phi\in C[0,1]$ with $\int_0^1\phi \, dx=0$,we have $\int_0^1f\phi \, dx=0$. Then $f$ is constant.

May be someone can help me proof this problem. Thanks!

Solutions Collecting From Web of "How to prove the function is a constant"

Let $c=\int_0^1fdx$ and let $\phi=f-c$. Then $\phi\in C[0,1]$ and $\int_0^1\phi dx=0$. Therefore,
$$0\le \int_0^1\phi^2 dx=\int_0^1f\phi dx-c\int_0^1\phi dx=0.$$
It follows that $\phi\equiv 0$, i.e. $f\equiv c$.

Here’s an outline for how to proceed. If $f$ is not constant, then $f$ has a maximum value $M$ that is strictly larger than its minimum value $m$. Assume $f(x_1) = M$ and $f(x_2) = m$. Choose $\phi$ to be positive in a small neighborhood of $x_1$, negative in a small neighborhood of $x_2$, and zero everywhere else, so that $\phi$ is continuous and $\int_0^1 \phi \, dx = 0$. Then argue that $\int_0^1 f \phi \, dx > 0$. (This will dictate how small to make your neighborhoods.)