
SolrDocument::toArray 메서드는 Elasticsearch의 문서를 배열로 변환합니다. toArray 메서드의 결과는 다음과 같습니다.
#hostingforum.kr
php
[
'id' => 1,
'name' => 'John Doe'
]
toArray 메서드의 결과를 사용하려면, 결과 배열을 변수에 저장하거나, 다른 함수에 전달할 수 있습니다. 예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$array = $solrDocument->toArray();
print_r($array); // 결과를 출력합니다.
또는, toArray 메서드의 결과를 다른 함수에 전달할 수 있습니다.
#hostingforum.kr
php
function printDocument(array $document): void
{
echo $document['id'] . ' ' . $document['name'] . "n";
}
$solrDocument = new SolrDocument();
$solrDocument->addField('id', 1);
$solrDocument->addField('name', 'John Doe');
printDocument($solrDocument->toArray());
toArray 메서드의 결과를 사용할 때는, 결과 배열의 키와 값에 주의해야 합니다. 키는 문서의 필드 이름을 나타내고, 값은 문서의 필드 값을 나타냅니다.
2025-03-05 05:16