Check if the shop is open or closed
Easiest solution (to the time problem) is to change your logic (just a tiny bit).


if ($time &gt;= $from &amp;&amp; $time &lt;= $to)



To:

if (($to &gt; $from &amp;&amp; ($time &gt;= $from &amp;&amp; $time &lt;= $to)) || 
    ($to &lt; $from &amp;&amp; ($time &gt;= $from || $time &lt;= $to)))


You just change whether to restrict the time to be between the two, or to restrict it to be greater than one or less than the other in the case that the $to time is less than $from.



As far as cleaning up your code: this is about as idiomatic as php will get. Though you should definitely extract this to a function as appropriate.