라이브러리
[PHP] MongoDBBSONDocument::has - 문서에 키가 있는지 여부를 반환합니다.
MongoDBBSONDocument::has()
`MongoDBBSONDocument::has()`는 MongoDBBSONDocument 인스턴스에 특정 필드가 존재하는지 확인하는 메서드입니다. 이 메서드는 필드가 존재하는지 여부를 boolean 값으로 반환합니다.
사용법
`has()` 메서드는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
use MongoDBBSONDocument;
$document = new Document();
$document->set('name', 'John Doe');
$document->set('age', 30);
var_dump($document->has('name')); // bool(true)
var_dump($document->has('age')); // bool(true)
var_dump($document->has('email')); // bool(false)
예제
다음 예제는 `has()` 메서드를 사용하여 MongoDBBSONDocument 인스턴스의 필드를 확인하는 방법을 보여줍니다.
#hostingforum.kr
php
use MongoDBBSONDocument;
// MongoDBBSONDocument 인스턴스 생성
$document = new Document();
// 필드 추가
$document->set('name', 'John Doe');
$document->set('age', 30);
// 필드가 존재하는지 확인
if ($document->has('name')) {
echo "name 필드는 존재합니다.
";
} else {
echo "name 필드는 존재하지 않습니다.
";
}
if ($document->has('age')) {
echo "age 필드는 존재합니다.
";
} else {
echo "age 필드는 존재하지 않습니다.
";
}
if ($document->has('email')) {
echo "email 필드는 존재합니다.
";
} else {
echo "email 필드는 존재하지 않습니다.
";
}
결과
#hostingforum.kr
name 필드는 존재합니다.
age 필드는 존재합니다.
email 필드는 존재하지 않습니다.
결론
`MongoDBBSONDocument::has()` 메서드는 MongoDBBSONDocument 인스턴스에 특정 필드가 존재하는지 확인하는 데 사용할 수 있습니다. 이 메서드는 필드가 존재하는지 여부를 boolean 값으로 반환합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.