본문 바로가기

헬퍼

번역일: 2026년 6월 20일

헬퍼

소개

Laravel은 다양한 전역 PHP "헬퍼" 함수를 제공합니다. 이 중 상당수는 프레임워크 내부에서 사용되지만, 필요에 따라 애플리케이션에서 자유롭게 활용할 수 있습니다.

사용 가능한 메서드

배열 & 객체

숫자

경로

URL

기타

배열 & 객체

`Arr::accessible()` {.collection-method .first-collection-method}

Arr::accessible 메서드는 주어진 값이 배열처럼 접근 가능한지 확인합니다:

use Illuminate\Support\Arr; use Illuminate\Support\Collection; $isAccessible = Arr::accessible(['a' => 1, 'b' => 2]); // true $isAccessible = Arr::accessible(new Collection); // true $isAccessible = Arr::accessible('abc'); // false $isAccessible = Arr::accessible(new stdClass); // false

`Arr::add()` {.collection-method}

Arr::add 메서드는 배열에 해당 키가 존재하지 않거나 값이 null인 경우에만 키/값 쌍을 추가합니다:

use Illuminate\Support\Arr; $array = Arr::add(['name' => 'Desk'], 'price', 100); // ['name' => 'Desk', 'price' => 100] $array = Arr::add(['name' => 'Desk', 'price' => null], 'price', 100); // ['name' => 'Desk', 'price' => 100]

`Arr::collapse()` {.collection-method}

Arr::collapse 메서드는 배열의 배열을 하나의 배열로 합칩니다:

use Illuminate\Support\Arr; $array = Arr::collapse([[1, 2, 3], [4, 5, 6], [7, 8, 9]]); // [1, 2, 3, 4, 5, 6, 7, 8, 9]

`Arr::crossJoin()` {.collection-method}

Arr::crossJoin 메서드는 주어진 배열들의 카테시안 곱(Cartesian product)을 반환합니다. 가능한 모든 순열 조합을 생성합니다:

use Illuminate\Support\Arr; $matrix = Arr::crossJoin([1, 2], ['a', 'b']); /* [ [1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'], ] */ $matrix = Arr::crossJoin([1, 2], ['a', 'b'], ['I', 'II']); /* [ [1, 'a', 'I'], [1, 'a', 'II'], [1, 'b', 'I'], [1, 'b', 'II'], [2, 'a', 'I'], [2, 'a', 'II'], [2, 'b', 'I'], [2, 'b', 'II'], ] */

`Arr::divide()` {.collection-method}

Arr::divide 메서드는 배열을 키 배열과 값 배열로 분리하여 두 개의 배열을 반환합니다:

use Illuminate\Support\Arr; [$keys, $values] = Arr::divide(['name' => 'Desk']); // $keys: ['name'] // $values: ['Desk']

`Arr::dot()` {.collection-method}

Arr::dot 메서드는 다차원 배열을 "점(dot)" 표기법을 사용한 단일 레벨 배열로 변환합니다:

use Illuminate\Support\Arr; $array = ['products' => ['desk' => ['price' => 100]]]; $flattened = Arr::dot($array); // ['products.desk.price' => 100]

`Arr::except()` {.collection-method}

Arr::except 메서드는 배열에서 지정한 키/값 쌍을 제거합니다:

use Illuminate\Support\Arr; $array = ['name' => 'Desk', 'price' => 100]; $filtered = Arr::except($array, ['price']); // ['name' => 'Desk']

`Arr::exists()` {.collection-method}

Arr::exists 메서드는 주어진 키가 배열에 존재하는지 확인합니다:

use Illuminate\Support\Arr; $array = ['name' => '홍길동', 'age' => 17]; $exists = Arr::exists($array, 'name'); // true $exists = Arr::exists($array, 'salary'); // false

`Arr::first()` {.collection-method}

Arr::first 메서드는 주어진 조건을 통과하는 배열의 첫 번째 요소를 반환합니다:

use Illuminate\Support\Arr; $array = [100, 200, 300]; $first = Arr::first($array, function (int $value, int $key) { return $value >= 150; }); // 200

세 번째 인자로 기본값을 전달할 수 있으며, 조건을 만족하는 값이 없을 경우 기본값이 반환됩니다:

use Illuminate\Support\Arr; $first = Arr::first($array, $callback, $default);

`Arr::flatten()` {.collection-method}

Arr::flatten 메서드는 다차원 배열을 단일 레벨 배열로 평탄화합니다:

use Illuminate\Support\Arr; $array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']]; $flattened = Arr::flatten($array); // ['Joe', 'PHP', 'Ruby']

`Arr::forget()` {.collection-method}

Arr::forget 메서드는 "점(dot)" 표기법을 사용해 깊이 중첩된 배열에서 특정 키/값 쌍을 제거합니다:

use Illuminate\Support\Arr; $array = ['products' => ['desk' => ['price' => 100]]]; Arr::forget($array, 'products.desk'); // ['products' => []]

`Arr::get()` {.collection-method}

Arr::get 메서드는 "점(dot)" 표기법을 사용해 깊이 중첩된 배열에서 값을 가져옵니다:

use Illuminate\Support\Arr; $array = ['products' => ['desk' => ['price' => 100]]]; $price = Arr::get($array, 'products.desk.price'); // 100

지정한 키가 없는 경우 반환할 기본값을 두 번째 인자로 전달할 수 있습니다:

use Illuminate\Support\Arr; $discount = Arr::get($array, 'products.desk.discount', 0); // 0

`Arr::has()` {.collection-method}

Arr::has 메서드는 "점(dot)" 표기법을 사용해 배열에 특정 키(들)가 존재하는지 확인합니다:

use Illuminate\Support\Arr; $array = ['product' => ['name' => 'Desk', 'price' => 100]]; $contains = Arr::has($array, 'product.name'); // true $contains = Arr::has($array, ['product.price', 'product.discount']); // false

`Arr::hasAny()` {.collection-method}

Arr::hasAny 메서드는 "점(dot)" 표기법을 사용해 주어진 키 중 하나라도 배열에 존재하는지 확인합니다:

use Illuminate\Support\Arr; $array = ['product' => ['name' => 'Desk', 'price' => 100]]; $contains = Arr::hasAny($array, 'product.name'); // true $contains = Arr::hasAny($array, ['product.name', 'product.discount']); // true $contains = Arr::hasAny($array, ['category', 'product.discount']); // false

`Arr::isAssoc()` {.collection-method}

Arr::isAssoc 메서드는 주어진 배열이 연관 배열이면 true를 반환합니다. 0부터 시작하는 순차적인 정수 키를 갖지 않으면 연관 배열로 간주합니다:

use Illuminate\Support\Arr; $isAssoc = Arr::isAssoc(['product' => ['name' => 'Desk', 'price' => 100]]); // true $isAssoc = Arr::isAssoc([1, 2, 3]); // false

`Arr::isList()` {.collection-method}

Arr::isList 메서드는 배열의 키가 0부터 시작하는 순차적인 정수인 경우 true를 반환합니다:

use Illuminate\Support\Arr; $isList = Arr::isList(['foo', 'bar', 'baz']); // true $isList = Arr::isList(['product' => ['name' => 'Desk', 'price' => 100]]); // false

`Arr::join()` {.collection-method}

Arr::join 메서드는 배열 요소들을 문자열로 연결합니다. 두 번째 인자로 구분자를 지정하며, 세 번째 인자로 마지막 요소 앞에 사용할 구분자를 별도로 지정할 수 있습니다:

use Illuminate\Support\Arr; $array = ['Tailwind', 'Alpine', 'Laravel', 'Livewire']; $joined = Arr::join($array, ', '); // Tailwind, Alpine, Laravel, Livewire $joined = Arr::join($array, ', ', ' 그리고 '); // Tailwind, Alpine, Laravel 그리고 Livewire

`Arr::keyBy()` {.collection-method}

Arr::keyBy 메서드는 지정한 키를 기준으로 배열을 재색인합니다. 동일한 키가 여러 개 있으면 마지막 값만 남습니다:

use Illuminate\Support\Arr; $array = [ ['product_id' => 'prod-100', 'name' => 'Desk'], ['product_id' => 'prod-200', 'name' => 'Chair'], ]; $keyed = Arr::keyBy($array, 'product_id'); /* [ 'prod-100' => ['product_id' => 'prod-100', 'name' => 'Desk'], 'prod-200' => ['product_id' => 'prod-200', 'name' => 'Chair'], ] */

`Arr::last()` {.collection-method}

Arr::last 메서드는 주어진 조건을 통과하는 배열의 마지막 요소를 반환합니다:

use Illuminate\Support\Arr; $array = [100, 200, 300, 110]; $last = Arr::last($array, function (int $value, int $key) { return $value >= 150; }); // 300

세 번째 인자로 기본값을 전달할 수 있으며, 조건을 만족하는 값이 없을 경우 기본값이 반환됩니다:

use Illuminate\Support\Arr; $last = Arr::last($array, $callback, $default);

`Arr::map()` {.collection-method}

Arr::map 메서드는 배열을 순회하며 각 값과 키를 콜백에 전달합니다. 콜백이 반환한 값으로 배열 요소가 교체됩니다:

use Illuminate\Support\Arr; $array = ['first' => 'james', 'last' => 'kirk']; $mapped = Arr::map($array, function (string $value, string $key) { return ucfirst($value); }); // ['first' => 'James', 'last' => 'Kirk']

`Arr::mapWithKeys()` {.collection-method}

Arr::mapWithKeys 메서드는 배열을 순회하며 각 값을 콜백에 전달합니다. 콜백은 단일 키/값 쌍을 담은 연관 배열을 반환해야 합니다:

use Illuminate\Support\Arr; $array = [ [ 'name' => '김민준', 'department' => '영업', 'email' => 'minjun@example.com', ], [ 'name' => '이지은', 'department' => '마케팅', 'email' => 'jieun@example.com', ] ]; $mapped = Arr::mapWithKeys($array, function (array $item, int $key) { return [$item['email'] => $item['name']]; }); /* [ 'minjun@example.com' => '김민준', 'jieun@example.com' => '이지은', ] */

`Arr::only()` {.collection-method}

Arr::only 메서드는 배열에서 지정한 키/값 쌍만 반환합니다:

use Illuminate\Support\Arr; $array = ['name' => 'Desk', 'price' => 100, 'orders' => 10]; $slice = Arr::only($array, ['name', 'price']); // ['name' => 'Desk', 'price' => 100]

`Arr::pluck()` {.collection-method}

Arr::pluck 메서드는 배열에서 지정한 키의 모든 값을 가져옵니다:

use Illuminate\Support\Arr; $array = [ ['developer' => ['id' => 1, 'name' => 'Taylor']], ['developer' => ['id' => 2, 'name' => 'Abigail']], ]; $names = Arr::pluck($array, 'developer.name'); // ['Taylor', 'Abigail']

결과 배열의 키를 별도로 지정할 수도 있습니다:

use Illuminate\Support\Arr; $names = Arr::pluck($array, 'developer.name', 'developer.id'); // [1 => 'Taylor', 2 => 'Abigail']

`Arr::prepend()` {.collection-method}

Arr::prepend 메서드는 배열의 맨 앞에 항목을 추가합니다:

use Illuminate\Support\Arr; $array = ['one', 'two', 'three', 'four']; $array = Arr::prepend($array, 'zero'); // ['zero', 'one', 'two', 'three', 'four']

필요하다면 값에 사용할 키를 지정할 수 있습니다:

use Illuminate\Support\Arr; $array = ['price' => 100]; $array = Arr::prepend($array, 'Desk', 'name'); // ['name' => 'Desk', 'price' => 100]

`Arr::prependKeysWith()` {.collection-method}

Arr::prependKeysWith 메서드는 연관 배열의 모든 키 앞에 지정한 접두사를 붙입니다:

use Illuminate\Support\Arr; $array = [ 'name' => 'Desk', 'price' => 100, ]; $keyed = Arr::prependKeysWith($array, 'product.'); /* [ 'product.name' => 'Desk', 'product.price' => 100, ] */

`Arr::pull()` {.collection-method}

Arr::pull 메서드는 배열에서 키/값 쌍을 제거하고 해당 값을 반환합니다:

use Illuminate\Support\Arr; $array = ['name' => 'Desk', 'price' => 100]; $name = Arr::pull($array, 'name'); // $name: Desk // $array: ['price' => 100]

세 번째 인자로 기본값을 전달할 수 있으며, 키가 없는 경우 기본값이 반환됩니다:

use Illuminate\Support\Arr; $value = Arr::pull($array, $key, $default);

`Arr::query()` {.collection-method}

Arr::query 메서드는 배열을 쿼리 문자열로 변환합니다:

use Illuminate\Support\Arr; $array = [ 'name' => 'Taylor', 'order' => [ 'column' => 'created_at', 'direction' => 'desc' ] ]; Arr::query($array); // name=Taylor&order[column]=created_at&order[direction]=desc

`Arr::random()` {.collection-method}

Arr::random 메서드는 배열에서 무작위로 값을 하나 반환합니다:

use Illuminate\Support\Arr; $array = [1, 2, 3, 4, 5]; $random = Arr::random($array); // 4 - (무작위로 선택됨)

두 번째 인자로 반환할 항목의 수를 지정할 수도 있습니다. 이 경우 항목이 하나뿐이어도 배열로 반환됩니다:

use Illuminate\Support\Arr; $items = Arr::random($array, 2); // [2, 5] - (무작위로 선택됨)

`Arr::set()` {.collection-method}

Arr::set 메서드는 "점(dot)" 표기법을 사용해 깊이 중첩된 배열에 값을 설정합니다:

use Illuminate\Support\Arr; $array = ['products' => ['desk' => ['price' => 100]]]; Arr::set($array, 'products.desk.price', 200); // ['products' => ['desk' => ['price' => 200]]]

`Arr::shuffle()` {.collection-method}

Arr::shuffle 메서드는 배열의 항목을 무작위로 섞습니다:

use Illuminate\Support\Arr; $array = Arr::shuffle([1, 2, 3, 4, 5]); // [3, 2, 5, 1, 4] - (무작위로 생성됨)

`Arr::sort()` {.collection-method}

Arr::sort 메서드는 배열을 값 기준으로 오름차순 정렬합니다:

use Illuminate\Support\Arr; $array = ['Desk', 'Table', 'Chair']; $sorted = Arr::sort($array); // ['Chair', 'Desk', 'Table']

클로저를 사용해 특정 기준으로 정렬할 수도 있습니다:

use Illuminate\Support\Arr; $array = [ ['name' => 'Desk'], ['name' => 'Table'], ['name' => 'Chair'], ]; $sorted = array_values(Arr::sort($array, function (array $value) { return $value['name']; })); /* [ ['name' => 'Chair'], ['name' => 'Desk'], ['name' => 'Table'], ] */

`Arr::sortDesc()` {.collection-method}

Arr::sortDesc 메서드는 배열을 값 기준으로 내림차순 정렬합니다:

use Illuminate\Support\Arr; $array = ['Desk', 'Table', 'Chair']; $sorted = Arr::sortDesc($array); // ['Table', 'Desk', 'Chair']

클로저를 사용해 특정 기준으로 내림차순 정렬할 수도 있습니다:

use Illuminate\Support\Arr; $

이 문서는 Laravel 공식 문서(MIT)를 한국 개발자를 위해 번역·재구성한 것입니다.

번역일: 2026년 6월 20일