PHP uasort() 함수
예시
사용자 정의 비교 함수를 사용하여 값을 기준으로 $arr 배열의 요소를 정렬합니다.
<?php
function my_sort($a,$b)
{
if ($a==$b) return 0;
return ($a<$b)?-1:1;
}
$arr=array("a"=>4,"b"=>2,"c"=>8,"d"=>6);
uasort($arr,"my_sort");
?>
정의 및 사용
uasort() 함수는 사용자 정의 비교 함수를 사용하여 값을 기준으로 배열을 정렬합니다.
팁: uksort() 함수를 사용 하여 사용자 정의 비교 함수를 사용하여 키로 배열을 정렬합니다.
통사론
uasort(array, myfunction)
매개변수 값
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
myfunction | Optional. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument |
기술적 세부 사항
반환 값: | 성공 시 TRUE입니다. 실패시 FALSE |
---|---|
PHP 버전: | 4+ |
❮ PHP 배열 참조