PHP 길이우선정렬

1 개요[ | ]

PHP 길이우선정렬
$fruits = ['banana','melon','pineapple','apple','lemon'];
usort($fruits, function($a,$b) {
    $lendiff = strlen($a) - strlen($b);
    return ($lendiff == 0) ? strcmp($a,$b) : $lendiff;
});
print_r($fruits);
$fruits = ['apple22','apple1','apple2','apple1','apple','lemon'];
usort($fruits, function($a,$b) {
    $lendiff = strlen($a) - strlen($b);
    return ($lendiff == 0) ? strcmp($a,$b) : $lendiff;
});
print_r($fruits);
$fruits = ['바나나','멜론','파인애플','사과','레몬'];
usort($fruits, function($a,$b) {
    $lendiff = strlen($a) - strlen($b);
    return ($lendiff == 0) ? strcmp($a,$b) : $lendiff;
});
print_r($fruits);

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}