Php &燃气轮机;值为负时失败
我有以下代码:Php &燃气轮机;值为负时失败,php,Php,我有以下代码: // evaluates to negative numbers, i.e. -2 $group_vids_count = $_videos->countGroupVids($series['id']) - 3; if ( $group_vids_count > 0 ) { $xmore = $group_vids_count . ' is more'; } else { $xmore = $group_vids_count; } 如果$group\
// evaluates to negative numbers, i.e. -2
$group_vids_count = $_videos->countGroupVids($series['id']) - 3;
if ( $group_vids_count > 0 )
{
$xmore = $group_vids_count . ' is more';
}
else
{
$xmore = $group_vids_count;
}
如果$group\u vids\u count
的计算结果为正数,则一切正常。就其计算结果为负数而言,如-2,尽管-2小于0,但我仍然会得到类似于$group\u vids\u count>0的结果
$\u videos->countGroupVids($series['id'])-3
用于直接显示3个视频。我需要知道还有多少
我曾尝试使用max()
,但仍然存在相同的问题…我无法重现该问题,请参阅。您确定$group\u vids\u count
实际上是负数吗?您的逻辑有问题请尝试此代码,它工作正常
<?php
$group_vids_count = -2;
if ( $group_vids_count > 0 )
{
$xmore = "possitive";
}
else
{
$xmore = "negative";
}
echo $xmore;
出于某种原因$group\u vids\u count=max(0,$group\u vids\u count)代码>现在做了这个把戏。。。Thanx所有人…这对你遇到的奇怪错误没有任何帮助,为什么你不简单地测试一下$vids\u count>3
?你肯定$\u videos->countgroupvides($series['id'])-3===-2
?@Michael-是的,因为我有一个包含1个视频的系列,so-3=-2@knittl-不能这样做,因为我还需要找出视频的数量3@MichalPlško但是您实际上已经通过回显值验证了方法countGroupVids()
是否正常工作并返回了它应该返回的值?