The interesting thing is that the period of the motion will be the same in both cases but the horizontal spring must also obey Hooke's law in compression.
For the vertical spring let the unit vector in the down direction be $\hat d$.
Using Newton's second law for the static equilibrium position $mg\, \hat d-kx_0 \,\hat d = 0\, \hat d \Rightarrow mg = kx_0$.
Now consider the spring stretch an extra amount $x$ from its equilibrium position.
$mg\, \hat d -k(x_0+x) \,\hat d = ma \,\hat d \Rightarrow -kx = ma$ which is exactly the same equation of motion you would get for a horizontal spring with $x$ as the actual extension of the spring as for a horizontal spring the equilibrium position would be with the spring unextended.
Update in response to a question from the OP.
If the spring is horizontal and extended from its unstretched state in the $\hat x$ direction by an amount $x$ then applying Newton’s second law gives $-kx \,\hat x = ma\,\hat x\Rightarrow -kx = ma$.
If the spring-mass system is on a slope you will get the same equation of motion but a changed static equilibrium extension $x_0$.
Is is as though the gravitational field strength $g$ had been reduced.