Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP将时间戳数组转换为MongoDB ObjectId_Php_Mongodb_Codeigniter - Fatal编程技术网

使用PHP将时间戳数组转换为MongoDB ObjectId

使用PHP将时间戳数组转换为MongoDB ObjectId,php,mongodb,codeigniter,Php,Mongodb,Codeigniter,我使用第三方API从使用PHP的MongoDB获得价值。我得到Mongo ObjectId作为时间戳数组,如下所示。如何将其转换为原始MongoDB ObjectId Array( [timestamp] => 1573559942 [machineIdentifier] => some value [processIdentifier] => some Value [counter] => 8306872

我使用第三方API从使用PHP的MongoDB获得价值。我得到Mongo ObjectId作为时间戳数组,如下所示。如何将其转换为原始MongoDB ObjectId

Array(
        [timestamp] => 1573559942
        [machineIdentifier] => some value
        [processIdentifier] => some Value
        [counter] => 8306872
        [date] => 2019-11-12T11:59:02.000+0000
        [time] => 1573559942000
        [timeSecond] => 1573559942
)

下面的代码可能会解决您的问题

$key = '';
$key .= dechex($arr['timestamp']&0xffffffff);
$key .= dechex($arr['machineIdentifier']&0xffffffff);
$key .= substr(dechex($arr['processIdentifier']&0xffffffff),-4);
$key .= dechex($arr['counter']&0xffffffff);

欢迎来到SO。这似乎是一个有效的答案,但请不要只发布代码答案。例如,在这里引用您的算法的源代码会很好。另请参阅: