Here is the code that can be function within a file:
For PHP part, you should pass value to the function and call the function.
I guess you need return data to the client from the php function return. Then, for ajax part, you have to catch the return data.
<?
if(isset($_POST['width'])){
$width = $_POST['width'];
function mobileView($width){
if ($width < 950){
echo 'true';
} else{
echo 'false';
}
}
mobileView($width);
}else{
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
htmlWidth = $("html").width();
$.ajax({
type: "POST",
url: "mobileView.php",
data:{ width: htmlWidth },
success: function(data){
console.log(data);
}
})
</script>
<?
};
?>