如何将js var分配给php var

I'm having a struggle with the php code below

<?php
$list = 0;
$screenWidth = '<script 
type="text/javascript">document.write(screen.availWidth);</script>';

if($screenWidth > 700){
   $list = 1;
}

echo $screenWidth; 
?>

The echo is printing the value of $screenWidth (screen width) correctly.

So it means the js works and is assigning the value from screen.availWidth to $screenWidth correctly but somehow $list is always 0 ! Even when the screen width is 1920

Thanks for your help!

Ceco

Your code doesnt echo the Screen width, it echoes the js:

echo '<script  type="text/javascript">document.write(screen.availWidth);</script>';

And on client side, this JS runs and prints out the screen width ( document.write).

However, as $screenWidth is a String, comparing it to 700 is not really working...