PHP中的interval()返回空字符串


intval() in php returns empty string?

谁能向我解释一下为什么这个(可疑的,过时的,否则有罪的)PHP代码偶尔返回一个包含两个星号字符一个接一个的字符串?换句话说,intval()偶尔会返回一个空字符串。

avcost列的值是多少(avcost被定义为double)?

$rows = mysql_query("SELECT avcost FROM singles" );
if (!$rows) return 5;
$buffer = "";
while ($row = mysql_fetch_row($rows))
{
    $avcost = intval($row[0]); // round it
    $buffer .= $avcost . "*";
}
echo $buffer; // Sometimes it echos something like: 5*0*3*0*34**4*5*

一个完整的答案应该包括对上面代码的最小修正(不使用像"if ($avcost == ")"这样的东西)。:-),保证输出中没有双星号。谢谢你。

一个完整的答案应该包括对上面代码的最小修正(不使用像"if ($avcost == ")"这样的东西)。:-),保证输出中没有双星号。谢谢你。

我试试看:-)

$rows = mysql_query("SELECT `avcost` FROM `singles`");
if (!$rows) return 5;
$buffer = "";
if (mysql_num_rows($rows) == 0) return 5; // Just if you want
while ($row = mysql_fetch_assoc($rows))
{
    $avcost = round($row['avcost']); // round it
    $buffer .= $avcost . "*";
}
echo $buffer; // Sometimes it echos something like: 5*0*3*0*34**4*5*

如果它不能工作,试试这个,并提供给我输出:

$rows = mysql_query("SELECT `avcost` FROM `singles`");
if (!$rows) return 5;
$buffer = "";
if (mysql_num_rows($rows) == 0) return 5; // Just if you want
while ($row = mysql_fetch_assoc($rows))
{
    $avcost = round($row['avcost']); // round it
    die(var_dump($avcost, intval($avcost), doubleval($row['avcost']), $row['avcost'])); // Debug purpose
    $buffer .= $avcost . "*";
}
echo $buffer; // Sometimes it echos something like: 5*0*3*0*34**4*5*