라라벨 콜렉션 sortBy()

1 개요[ | ]

라라벨 sortBy()
$array = [
    ['id'=>1, 'name'=>'Carol'],
    ['id'=>2, 'name'=>'Alice'],
    ['id'=>3, 'name'=>'Bob'],
];
$sorted = collect($array)->sortBy('name')->toArray();
dd( $sorted );
# array:3 [
#   1 => array:2 [
#     "id" => 2
#     "name" => "Alice"
#   ]
#   2 => array:2 [
#     "id" => 3
#     "name" => "Bob"
#   ]
#   0 => array:2 [
#     "id" => 1
#     "name" => "Carol"
#   ]
# ]
$array = [
    ['id'=>1, 'name'=>'Carol'],
    ['id'=>2, 'name'=>'Alice'],
    ['id'=>3, 'name'=>'Bob'],
];
$sorted = collect($array)->sortBy('name')->values()->toArray();
dd( $sorted );
# array:3 [
#   0 => array:2 [
#     "id" => 2
#     "name" => "Alice"
#   ]
#   1 => array:2 [
#     "id" => 3
#     "name" => "Bob"
#   ]
#   2 => array:2 [
#     "id" => 1
#     "name" => "Carol"
#   ]
# ]

2 같이 보기[ | ]

3 참고[ | ]

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