
MongoDBBSONDocument::get 메서드는 반환 값에 따라 다르게 처리해야 합니다.
1. 배열: 반환 값이 배열일 경우, 메서드는 배열을 반환합니다. 예를 들어, 다음 코드는 필드가 배열인 경우를示しています.
#hostingforum.kr
php
$bsonDocument = new MongoDBBSONDocument();
$bsonDocument->set('arrayField', [1, 2, 3]);
$array = $bsonDocument->get('arrayField');
print_r($array); // Output: Array ( [0] => 1 [1] => 2 [2] => 3 )
2. null: 반환 값이 null일 경우, 메서드는 null을 반환합니다. 예를 들어, 다음 코드는 필드가 null인 경우를示しています.
#hostingforum.kr
php
$bsonDocument = new MongoDBBSONDocument();
$bsonDocument->set('nullField', null);
$null = $bsonDocument->get('nullField');
var_dump($null); // Output: NULL
3. 문자열: 반환 값이 문자열일 경우, 메서드는 문자열을 반환합니다. 예를 들어, 다음 코드는 필드가 문자열인 경우를示しています.
#hostingforum.kr
php
$bsonDocument = new MongoDBBSONDocument();
$bsonDocument->set('stringField', 'Hello, World!');
$string = $bsonDocument->get('stringField');
echo $string; // Output: Hello, World!
4. 숫자: 반환 값이 숫자일 경우, 메서드는 숫자를 반환합니다. 예를 들어, 다음 코드는 필드가 숫자인 경우를示しています.
#hostingforum.kr
php
$bsonDocument = new MongoDBBSONDocument();
$bsonDocument->set('numberField', 123);
$number = $bsonDocument->get('numberField');
echo $number; // Output: 123
5. 객체: 반환 값이 객체일 경우, 메서드는 객체를 반환합니다. 예를 들어, 다음 코드는 필드가 객체인 경우를示しています.
#hostingforum.kr
php
$bsonDocument = new MongoDBBSONDocument();
$object = new stdClass();
$object->name = 'John';
$object->age = 30;
$bsonDocument->set('objectField', $object);
$object = $bsonDocument->get('objectField');
echo $object->name; // Output: John
echo $object->age; // Output: 30
위의 예제를 통해 MongoDBBSONDocument::get 메서드가 반환하는 다양한 형태의 값을 다루는 방법을 이해할 수 있습니다.
2025-07-07 14:36