I just cannot get this to work… I have tried many things and spent the past 2 hours trying to work it out.
I am testing this on a screen width on 1920 and $screenWidth returns 1920 and if I change $screenWidth in the if else statement to 1920 then the if else statement works.
Note that the value is not what the server is outputting. It is outputting the script and the script is writing the value.
For this to work the way I think you have in mind you will need to have JavaScript in the browser send the value back to the server then have PHP send output depending on the value. Or do it entirely with JavaScript.
There are a few ways you could do this, but all have negatives. IMHO it would be a lot easier and much better to simply code the page so it displays OK regardless of screen width and avoid using complicated script hacks.