PHP array_chunk() 함수
예시
배열을 두 개의 청크로 분할합니다.
<?php
$cars=array("Volvo","BMW","Toyota","Honda","Mercedes","Opel");
print_r(array_chunk($cars,2));
?>
정의 및 사용
array_chunk() 함수는 배열을 새 배열의 청크로 분할합니다.
통사론
array_chunk(array, size, preserve_key)
매개변수 값
Parameter | Description |
---|---|
array | Required. Specifies the array to use |
size | Required. An integer that specifies the size of each chunk |
preserve_key | Optional. Possible values:
|
기술적 세부 사항
반환 값: | 크기 요소 를 포함하는 각 차원과 함께 0부터 시작하는 다차원 인덱스 배열을 반환합니다. |
---|---|
PHP 버전: | 4.2+ |
더 많은 예
예시
배열을 두 조각으로 나누고 원래 키를 유지합니다.
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43","Harry"=>"50");
print_r(array_chunk($age,2,true));
?>
❮ PHP 배열 참조