
PHP 배열을 MongoDB BSON Document로 변환하는 방법은 `MongoDBBSONDocument::fromPHP` 메서드를 사용하는 것입니다.
예를 들어, 다음과 같은 PHP 배열을 MongoDB BSON Document로 변환하는 코드는 다음과 같습니다.
#hostingforum.kr
php
$array = [
'name' => 'John Doe',
'age' => 30,
'address' => [
'street' => '123 Main St',
'city' => 'New York',
'state' => 'NY',
'zip' => '10001'
]
];
$document = new MongoDBBSONUTCDateTime();
$document = MongoDBBSONtoDocument($array);
print_r($document);
위의 코드는 `$array`를 MongoDB BSON Document로 변환합니다. `$document` 변수에는 변환된 MongoDB BSON Document가 저장됩니다.
`MongoDB\BSON\toDocument` 메서드는 PHP 배열을 MongoDB BSON Document로 변환하는 데 사용됩니다.
위의 코드를 실행하면 `$document` 변수에 다음과 같은 MongoDB BSON Document가 저장됩니다.
#hostingforum.kr
json
{
"_id" : ObjectId("..."),
"name" : "John Doe",
"age" : 30,
"address" : {
"street" : "123 Main St",
"city" : "New York",
"state" : "NY",
"zip" : "10001"
}
}
위의 코드는 MongoDB BSON Document를 생성하는 데 사용됩니다. MongoDB BSON Document는 MongoDB 데이터베이스에 저장됩니다.
위의 코드를 사용하여 PHP 배열을 MongoDB BSON Document로 변환할 수 있습니다.
2025-03-18 21:04