使用PHP将时间戳数组转换为MongoDB ObjectId
我使用第三方API从使用PHP的MongoDB获得价值。我得到Mongo ObjectId作为时间戳数组,如下所示。如何将其转换为原始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
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。这似乎是一个有效的答案,但请不要只发布代码答案。例如,在这里引用您的算法的源代码会很好。另请参阅: