PHP:测试两个双变量会给出不同的结果,而不会更改变量

在我的代码中我有两个双值.让我们称他们为$a和$b.现在我想测试哪一个更大,所以我写了以下内容:

print ($a > $b ? "larger\n" : "smaller\n");
print ($a > $b ? "larger\n" : "smaller\n");

奇怪的是结果是

larger
smaller

以前有人遇到过类似的问题吗?这个问题只出现在我们使用php-cgi的嵌入式linux系统上.

感谢您的回答和建议.

这是整个代码:我需要将十六进制值解码为关于符号的十进制值,并最终使用大于整数大小的数字

function decodeInteger($datahex)
{
    // ignore non hex characters
    $hex = preg_replace('/[^0-9A-Fa-f]/', '', $datahex);

    // converted decimal value as double:
    $dec = hexdec($hex) * 1.0;

    // maximum decimal value based on length of hex + 1:
    //   number of bits in hex number is 8 bits for each 2 hex-characters -> max = 2^n
    //   use 'pow(2.0,n)' since '1 << n' and 'pow(2,n)' is only for integers and therefore limited to integer size.
    $max = pow(2.0, 4 * (strlen($hex) + (strlen($hex) % 2)));

    // complement = maximum - converted hex:
    $_dec = $max - $dec;


    print ($dec > $_dec ? "larger\n" : "smaller\n");
    print ($dec > $_dec ? "larger\n" : "smaller\n");

    // if dec value is larger than its complement we have a negative value (first bit is set)
    return $dec > $_dec ? -$_dec : $dec;
}

解决方法:

请跑

var_dump($dec); var_dump($_dec); var_dump($dec); var_dump($_dec);
print ($dec > $_dec ? "larger\n" : "smaller\n");

var_dump($dec); var_dump($_dec); var_dump($dec); var_dump($_dec);
print ($dec > $_dec ? "larger\n" : "smaller\n");

并在此处发布输出. (很抱歉将此作为答案发布,但我的*信誉不允许发表评论)

上一篇:关于nginx配置的一个报错connect() to unix:/tmp/php-cgi.sock failed (2: No such file or directory)


下一篇:如何通过启用指令“short_open_tag”. Htaccess Apache [PHP 5.3]