MongoId
PHP Manual

MongoId::__construct

(PECL mongo >= 0.8.0)

MongoId::__constructCreates a new id

설명

MongoId::__construct ([ string $id= NULL ] )

인수

id

A string to use as the id.

반환값

Returns a new id.

예제

Example #1 MongoId::__construct() example

This example shows how to create a new id. This is seldom necessary, as the driver adds an id to arrays automatically before storing them in the database.

<?php

  $id1 
= new MongoId();
  echo 
"$id1\n";

  
$id1 = new MongoId();
  echo 
"$id2\n";

  
?>

위 예제의 출력 예시:

49a7011a05c677b9a916612a
49a702d5450046d3d515d10d

Note that the second hexidecimal number is greater than the first.

Example #2 Parameter example

This example shows how to use a string parameter to initialize a MongoId with a given value.

<?php
  $id1 
= new MongoId();

  
// create a new id from $id1
  
$id2 = new MongoId("$id1");

  
// show that $id1 and $id2 have the same hexidecimal value
  
var_dump($id1 == $id2);
  
?>

위 예제의 출력 예시:

bool(true)

참고


MongoId
PHP Manual