
MongoDBBSONDocument::getIterator는 MongoDBBSONDocument가 implements한 IteratorAggregate 인터페이스를 통해 Iterator를 반환합니다. 따라서, MongoDBBSONDocument::getIterator의 리턴 타입은 Traversable 타입입니다.
이 Traversable 타입을 사용하여 데이터를 가져올 수 있습니다. 예를 들어, foreach 문을 사용하여 데이터를 가져올 수 있습니다.
#hostingforum.kr
php
$bsonDocument = new MongoDBBSONDocument();
$bsonDocument->append('key1', 'value1');
$bsonDocument->append('key2', 'value2');
foreach ($bsonDocument->getIterator() as $key => $value) {
echo "Key: $key, Value: $valuen";
}
또한, Traversable 타입은 array를 반환하는 함수에 전달할 수 있습니다.
#hostingforum.kr
php
$bsonDocument = new MongoDBBSONDocument();
$bsonDocument->append('key1', 'value1');
$bsonDocument->append('key2', 'value2');
$array = iterator_to_array($bsonDocument->getIterator());
print_r($array);
이러한 예제를 통해 MongoDBBSONDocument::getIterator를 사용하여 데이터를 가져올 수 있는 방법을 확인할 수 있습니다.
2025-06-13 23:31