简体   繁体   English

带变量检查的条件is_int?

[英]Conditional is_int with variable check?

I've got this snippet of code that I am trying to understand what it does.. Any help would be awesome 我有一段代码,我试图了解它的作用。.任何帮助都会很棒

$returnValue= 0;

if (is_int($bottleNumber/12)){
    $returnValue=1;
}

echo $_GET['callback']. '('. json_encode($returnValue) . ')'; 

It prints out Javascript code to call the function named in $_GET['callback'] . 它打印出Javascript代码以调用$_GET['callback']命名的函数。

If the URL is mypage.php?callback=alert , it will check to see if $bottleNumber is a multiple of 12, then write 如果URL是mypage.php?callback=alert ,它将检查$bottleNumber是否为12的倍数,然后编写

alert(1)

if it was (or alert(0) if it wasn't). 如果是(如果不是,则为alert(0) )。

The callback parameter could be anything, so you can change the job of the script by changing the one parameter. callback参数可以是任何值,因此您可以通过更改一个参数来更改脚本的工作。

thats rendering JSONP response read more here 多数民众赞成在呈现JSONP响应在这里阅读更多

http://www.geekality.net/2010/06/27/php-how-to-easily-provide-json-and-jsonp/ http://www.geekality.net/2010/06/27/php-how-to-easily-provide-json-and-jsonp/

First, you see that it is setting up everything as false. 首先,您会看到将所有内容都设置为false。

$returnValue= 0;

This is not necessary, but good practice to ensure that you get proper results. 这不是必需的,但是是确保您获得正确结果的良好实践。

if (is_int($bottleNumber/12)){
    $returnValue=1;
}

Here, $bottleNumber is divided by 12. If that number is an integer (no remainder), then we know it is divisible by 12. Order of operations much like normal math here. 在这里,$ bottleNumber除以12。如果该数字是整数(无余数),则我们知道它可以被12整除。操作顺序与此处的正常数学非常相似。 If it is cleanly divisible by 12, then we take note of it and hit our switch. 如果它可以被12整除,那么我们记下它并按下开关。

Now, we return either 1 or 0. This is why we set $returnvalue to 0 originally. 现在,我们返回1或0。这就是为什么我们最初将$ returnvalue设置为0的原因。 It's a 'fallback' value. 这是一个“后备”值。

This checks if a number is divisible by 12 and returns an appropriate JSON response 这将检查数字是否可被12整除并返回适当的JSON响应

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM