라이브러리

[PHP] MongoDBBSONDocument::toPHP - BSON 문서의 PHP 표현을 반환합니다.




MongoDBBSONDocument::toPHP

`MongoDBBSONDocument::toPHP`은 MongoDB의 BSON 문서를 PHP 객체로 변환하는 메서드입니다. 이 메서드는 MongoDB의 BSON 문서를 PHP의 객체로 변환하는 데 사용됩니다. 이 객체는 PHP의 `stdClass` 객체와 유사하며, PHP의 객체를 MongoDB의 BSON 문서로 변환하는 데 사용됩니다.

예제


#hostingforum.kr
php

// MongoDB의 BSON 문서

$document = new MongoDBBSONUTCDateTime();

$document->setTimestamp(1643723400);



// MongoDBBSONDocument::toPHP을 사용하여 PHP 객체로 변환

$obj = $document->toPHP();



// PHP 객체의 프로퍼티를 출력

echo $obj->getTimestamp(); // 1643723400



사용 방법


1. MongoDB의 BSON 문서를 생성합니다.
2. `MongoDBBSONDocument::toPHP` 메서드를 사용하여 PHP 객체로 변환합니다.
3. PHP 객체의 프로퍼티를 사용합니다.

예제 2


#hostingforum.kr
php

// MongoDB의 BSON 문서

$document = new MongoDBBSONDocument();

$document->set('name', 'John Doe');

$document->set('age', 30);



// MongoDBBSONDocument::toPHP을 사용하여 PHP 객체로 변환

$obj = $document->toPHP();



// PHP 객체의 프로퍼티를 출력

echo $obj->name; // John Doe

echo $obj->age; // 30



예제 3


#hostingforum.kr
php

// MongoDB의 BSON 문서

$document = new MongoDBBSONDocument();

$document->set('name', 'Jane Doe');

$document->set('age', 25);

$document->set('address', new MongoDBBSONDocument(['street' => '123 Main St', 'city' => 'Anytown', 'state' => 'CA', 'zip' => '12345']));



// MongoDBBSONDocument::toPHP을 사용하여 PHP 객체로 변환

$obj = $document->toPHP();



// PHP 객체의 프로퍼티를 출력

echo $obj->name; // Jane Doe

echo $obj->age; // 25

echo $obj->address->street; // 123 Main St

echo $obj->address->city; // Anytown

echo $obj->address->state; // CA

echo $obj->address->zip; // 12345



참고


* `MongoDBBSONDocument::toPHP` 메서드는 MongoDB의 BSON 문서를 PHP 객체로 변환하는 데 사용됩니다.
* 이 메서드는 PHP 객체를 MongoDB의 BSON 문서로 변환하는 데 사용되지 않습니다.
* PHP 객체의 프로퍼티는 MongoDB의 BSON 문서의 필드와 유사합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 340 페이지

검색

게시물 검색