라이브러리

[PHP] Collator::sortWithSortKeys - 지정된 정렬기 및 정렬 키를 사용하여 배열 정렬




PHP의 Collator 클래스는 문자열을 정렬하는 데 사용되는 클래스입니다. Collator::sortWithSortKeys 메소드는 문자열을 정렬할 때, 정렬 키를 사용하여 정렬을 수행하는 메소드입니다.

Collator::sortWithSortKeys 메소드


Collator::sortWithSortKeys 메소드는 Collator 객체를 사용하여 정렬을 수행할 수 있습니다. 이 메소드는 정렬 키를 사용하여 정렬을 수행하므로, 정렬 결과가 더 정확하고 예측 가능한 결과를 반환합니다.

예제


#hostingforum.kr
php

// Collator 객체를 생성합니다.

$collator = new Collator('ko_KR');



// 정렬할 문자열을 준비합니다.

$strings = array('apple', 'banana', 'cherry', 'date', 'elderberry');



// Collator::sortWithSortKeys 메소드를 사용하여 정렬을 수행합니다.

usort($strings, function($a, $b) use ($collator) {

    return $collator->compare($a, $b);

});



// 정렬된 결과를 출력합니다.

print_r($strings);



결과


#hostingforum.kr
php

Array

(

    [0] => apple

    [1] => banana

    [2] => cherry

    [3] => date

    [4] => elderberry

)



설명


Collator::sortWithSortKeys 메소드는 Collator 객체를 사용하여 정렬을 수행합니다. Collator 객체는 정렬 키를 사용하여 정렬을 수행하므로, 정렬 결과가 더 정확하고 예측 가능한 결과를 반환합니다.

Collator::sortWithSortKeys 메소드는 usort 함수와 함께 사용할 수 있습니다. usort 함수는 정렬된 결과를 반환합니다.

참고


Collator::sortWithSortKeys 메소드는 PHP 7.2 이상에서 사용할 수 있습니다. PHP 7.1 미만에서는 사용할 수 없습니다.

Collator 클래스는 PHP 7.2 이상에서 사용할 수 있습니다. PHP 7.1 미만에서는 사용할 수 없습니다.

결론


Collator::sortWithSortKeys 메소드는 문자열을 정렬할 때, 정렬 키를 사용하여 정렬을 수행하는 메소드입니다. 이 메소드는 Collator 객체를 사용하여 정렬을 수행할 수 있습니다. Collator::sortWithSortKeys 메소드는 usort 함수와 함께 사용할 수 있으며, 정렬된 결과를 반환합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색