라이브러리

[PHP] RecursiveTreeIterator::rewind - 되감기 반복자




RecursiveTreeIterator::rewind

RecursiveTreeIterator는 PHP의 SPL (Standard PHP Library) 모듈에 포함된 클래스입니다. 이 클래스는 트리 구조의 데이터를 반복처리하기 위해 사용됩니다. RecursiveTreeIterator::rewind 메소드는 반복처리에서 현재 위치를 초기화합니다.

사용법


RecursiveTreeIterator::rewind 메소드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/path/to/directory'));

$iterator->rewind();



예제


다음 예제는 RecursiveTreeIterator::rewind 메소드를 사용하여 디렉토리 트리 구조를 반복처리하는 방법을 보여줍니다.

#hostingforum.kr
php

// 디렉토리 트리 구조를 반복처리하기 위한 RecursiveIteratorIterator 객체 생성

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/path/to/directory'));



// 반복처리에서 현재 위치를 초기화합니다.

$iterator->rewind();



// 반복처리 결과를 출력합니다.

while ($iterator->valid()) {

    echo $iterator->getSubPathName() . ' : ' . $iterator->getFilename() . "
";

    $iterator->next();

}



결과


위 예제의 결과는 다음과 같습니다.

#hostingforum.kr


/path/to/directory : .

/path/to/directory/subdir1 : .

/path/to/directory/subdir1/file1.txt : .

/path/to/directory/subdir1/file2.txt : .

/path/to/directory/subdir2 : .

/path/to/directory/file3.txt : .



참고


RecursiveTreeIterator::rewind 메소드는 반복처리에서 현재 위치를 초기화합니다. 반복처리에서 현재 위치를 초기화하면, 반복처리에서 다시 시작할 수 있습니다. RecursiveTreeIterator::rewind 메소드는 반복처리에서 현재 위치를 초기화하는 데 사용됩니다.

예제 2


다음 예제는 RecursiveTreeIterator::rewind 메소드를 사용하여 XML 파일을 반복처리하는 방법을 보여줍니다.

#hostingforum.kr
php

// XML 파일을 반복처리하기 위한 RecursiveIteratorIterator 객체 생성

$xml = new SimpleXMLElement('John30');

$iterator = new RecursiveIteratorIterator(new RecursiveIteratorIterator($xml));



// 반복처리에서 현재 위치를 초기화합니다.

$iterator->rewind();



// 반복처리 결과를 출력합니다.

while ($iterator->valid()) {

    echo $iterator->getSubPathName() . ' : ' . $iterator->getFilename() . "
";

    $iterator->next();

}



결과


위 예제의 결과는 다음과 같습니다.

#hostingforum.kr


root : 

person : 

name : 

age : 



참고


RecursiveTreeIterator::rewind 메소드는 반복처리에서 현재 위치를 초기화합니다. 반복처리에서 현재 위치를 초기화하면, 반복처리에서 다시 시작할 수 있습니다. RecursiveTreeIterator::rewind 메소드는 반복처리에서 현재 위치를 초기화하는 데 사용됩니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 293 페이지

검색

게시물 검색