我使用第三方API通过PHP从MongoDB获取值。我得到MongoObjectId作为时间戳数组,如下所示。如何将其转换为原始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);