1 개요[ | ]
- 배열의 일부를 제거하거나 다른 것으로 교체하는 PHP 함수
PHP
CPU
0.0s
MEM
21M
0.2s
Copy
$colors = ['red', 'green', 'blue', 'yellow'];
array_splice($colors, 2);
print_r($colors);
Array ( [0] => red [1] => green )
PHP
Copy
$colors = ['red', 'green', 'blue', 'yellow'];
array_splice($colors, 1, -1);
print_r($colors);
Loading
PHP
Copy
$colors = ['red', 'green', 'blue', 'yellow'];
array_splice($colors, 1, count($colors), 'orange');
print_r($colors);
Loading
PHP
Copy
$colors = ['red', 'green', 'blue', 'yellow'];
array_splice($colors, -1, 1, ['black', 'maroon']);
print_r($colors);
Loading
2 같이 보기[ | ]
- PHP unset() - 변수 제거
- PHP array_slice() - 배열의 조각을 추출
- PHP array_merge() - 1개 이상의 배열을 병합
3 참고[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.