in_array
(PHP 4, PHP 5, PHP 7)
in_array — 값이 배열 안에 존재하는지 확인
설명 ¶
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
인수 ¶
needle
찾을 값.
Note:
needle이 문자열이면, 대소문자를 구분하여 비교합니다.
haystack
배열.
strict
세번째 인수 strict를 TRUE로 설정하면, in_array() 함수는 haystack 안에서 needle의 자료형도 확인합니다.
반환값 ¶
needle을 배열에서 찾으면 TRUE를, 아니면 FALSE를 반환합니다.
Example #1 in_array() 예제
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
in_array()가 대소문자를 구분하므로 두번째 조건은 실패하고, 위 프로그램은 다음을 출력합니다:
output :
Got Irix
Example #2 in_array()에 strict 예제
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check\n";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check\n";
}
?>
위 예제의 출력:
1.13 found with strict check
Example #3 in_array()에 needle로 배열
<?php
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' was found\n";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' was found\n";
}
if (in_array('o', $a)) {
echo "'o' was found\n";
}
?>
위 예제의 출력:
'ph' was found
'o' was found
댓글 1개
게시판 목록
팁게시판
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5502 | 11년 전 | 3846 | ||
| 5501 | 11년 전 | 1135 | ||
| 5500 |
잘살아보자
|
11년 전 | 900 | |
| 5499 |
kiplayer
|
11년 전 | 7433 | |
| 5498 |
잘살아보자
|
11년 전 | 2308 | |
| 5497 |
잘살아보자
|
11년 전 | 1127 | |
| 5496 |
잘살아보자
|
11년 전 | 1167 | |
| 5495 |
잘살아보자
|
11년 전 | 958 | |
| 5494 |
잘살아보자
|
11년 전 | 4552 | |
| 5493 |
잘살아보자
|
11년 전 | 672 | |
| 5492 |
잘살아보자
|
11년 전 | 5230 | |
| 5491 |
잘살아보자
|
11년 전 | 3376 | |
| 5490 | 11년 전 | 1187 | ||
| 5489 |
|
11년 전 | 3275 | |
| 5488 |
잘살아보자
|
11년 전 | 2822 | |
| 5487 |
잘살아보자
|
11년 전 | 2197 | |
| 5486 |
잘살아보자
|
11년 전 | 1437 | |
| 5485 |
잘살아보자
|
11년 전 | 1449 | |
| 5484 |
잘살아보자
|
11년 전 | 2332 | |
| 5483 |
잘살아보자
|
11년 전 | 3237 | |
| 5482 |
잘살아보자
|
11년 전 | 1124 | |
| 5481 |
잘살아보자
|
11년 전 | 734 | |
| 5480 |
잘살아보자
|
11년 전 | 1361 | |
| 5479 |
잘살아보자
|
11년 전 | 673 | |
| 5478 |
잘살아보자
|
11년 전 | 1252 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기