라이브러리
[PHP] CollectionModify::unset - 문서 필드 값 설정 해제
CollectionModify::unset
PHP의 SplObjectStorage 클래스는 객체를 관리하기 위한 내장 클래스입니다. 이 클래스는 객체를 추가하고 제거하는 메서드를 제공합니다. CollectionModify::unset은 SplObjectStorage 클래스의 메서드 중 하나로, 지정된 객체를 삭제하는 메서드입니다.
사용법
CollectionModify::unset 메서드는 다음과 같은 형식으로 사용할 수 있습니다.
#hostingforum.kr
php
CollectionModify::unset($storage, $object)
- `$storage` : SplObjectStorage 객체
- `$object` : 삭제할 객체
예제
#hostingforum.kr
php
// SplObjectStorage 객체 생성
$storage = new SplObjectStorage();
// 객체 생성
$obj1 = new stdClass();
$obj2 = new stdClass();
// 객체 추가
$storage->attach($obj1);
$storage->attach($obj2);
// 객체 목록 출력
echo "객체 목록:
";
foreach ($storage as $obj) {
echo get_class($obj) . "
";
}
// CollectionModify::unset 사용
$storage->detach($obj1);
// 객체 목록 출력
echo "
객체 목록 (obj1 삭제):
";
foreach ($storage as $obj) {
echo get_class($obj) . "
";
}
결과
객체 목록:
stdClass
stdClass
객체 목록 (obj1 삭제):
stdClass
위 예제에서, `$storage` 객체에 `$obj1`와 `$obj2` 객체가 추가됩니다. 그런 다음, `CollectionModify::unset` 메서드를 사용하여 `$obj1` 객체를 삭제합니다. 결과적으로 `$storage` 객체의 목록에서 `$obj1` 객체가 삭제됩니다.
참고
- SplObjectStorage 클래스는 객체를 관리하기 위한 내장 클래스입니다.
- CollectionModify::unset 메서드는 지정된 객체를 삭제하는 메서드입니다.
- `$storage` 객체에 `$obj1` 객체를 삭제하려면 `$storage->detach($obj1)` 메서드를 사용합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.