简体   繁体   English

php运算符有问题

[英]Having issues with php operator

I want to compare two values and if one is greater than the other then it performs some update in the database, however the result always returns false. 我想比较两个值,如果一个值大于另一个值,那么它将在数据库中执行一些更新,但是结果始终返回false。 this is an example of the part of the code im struggling with: 这是代码中苦苦挣扎的一部分的示例:

<?php 
$page = mysql_fetch_object(mysql_query("SELECT * FROM `site` WHERE `id`='{$posts['him']}'"));
$count = file_get_contents($site->site_url . 'count/numbercheck.php?url=' . ($page->url));
if(is_numeric($count) && $count > $posts['count'])
{
    echo 'true';
}else{
    echo 'false';   
}

?>

this echos false. 这回荡假。 The $posts['count'] comes from a jquery post on another page. $ posts ['count']来自另一页上的jquery帖子。 and I'm sure that $count is greater than $posts['count']. 并且我确定$ count大于$ posts ['count']。 And just to be sure then I did this: 只是要确保然后我这样做:

<?php 
$page = mysql_fetch_object(mysql_query("SELECT * FROM `site` WHERE `id`='{$posts['him']}'"));
$count = file_get_contents($site->site_url . '/count/numbercheck.php?url=' . ($page->url));
if(is_numeric($count) && $count > $posts['count'])
{
    echo 'true' . $count . ' ' . $posts['count'];
}else{
    echo 'false' . $count . ' ' . $posts['count'];  
}

?>

that returns "false 86 85". 返回“ false 86 85”。 I don't get it, what I am doing wrong? 我不明白,我做错了什么? its clear to me that 86 is greater than 85. 我清楚地知道86大于85。

file_get_contents() returns a string value so it is always going to evaluate as false when using is_numeric() file_get_contents()返回一个字符串值,因此在使用is_numeric()时它将始终被评估为false

If you want to return an array (one item for each line in the file), you should use file() instead of file_get_contents() 如果要返回一个数组(文件中每一行一项),则应使用file()而不是file_get_contents()

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

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