2

我正在为 jQuery 使用 flot 图形库,它对任何时间序列都使用 javascript 时间(提醒一下,这是自 1970 年 1 月以来的毫秒数。Unix 时间是seconds)。

我当前的代码如下所示:

foreach($decoded['results'] as $currentResult) {
         if($currentResult['from_user'] == $user) {
             $strippedTexts = $currentResult['created_at'];
             $dates []= strtotime($strippedTexts);
         }
    }

这给了我一组 Unix 时间戳。我想在循环中为 JavaScript 准备数据,但是当我尝试

$dates []= 1000*strtotime($strippedTexts);

数字太大,它会吐出“[-2147483648]”。我是否需要将允许在数组中保存的变量的“类型”更改为 bignum 之类的?

谢谢!

4

3 回答 3

3

试试这个:

$dates []= 1000.0*strtotime($strippedTexts);

这将把它变成浮点数,在 php 中它可以存储比 int 更大的数字。

于 2009-04-17T19:05:32.237 回答
2

如果有可用的BCMath 任意精度函数,您可以尝试使用它们:

$dates[] = bcmul("1000", strtotime($strippedTexts));

或者只是,你知道,在末尾附加三个零。

$dates[] = strtotime($strippedTexts).'000';

在这两种情况下,您最终都会将值存储为字符串,但这对您的使用无关紧要。

于 2009-04-17T19:02:51.977 回答
0

不需要解决方案,因为没有问题:让 JavaScript 来做乘法。

于 2009-09-27T05:45:06.410 回答