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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 396 | ||
| 7929 | 9년 전 | 312 | ||
| 7928 | 9년 전 | 404 | ||
| 7927 | 9년 전 | 325 | ||
| 7926 | 9년 전 | 655 | ||
| 7925 | 9년 전 | 339 | ||
| 7924 | 9년 전 | 326 | ||
| 7923 | 9년 전 | 332 | ||
| 7922 | 9년 전 | 365 | ||
| 7921 | 9년 전 | 394 | ||
| 7920 | 9년 전 | 312 | ||
| 7919 | 9년 전 | 330 | ||
| 7918 | 9년 전 | 484 | ||
| 7917 | 9년 전 | 323 | ||
| 7916 | 9년 전 | 397 | ||
| 7915 | 9년 전 | 395 | ||
| 7914 | 9년 전 | 403 | ||
| 7913 | 9년 전 | 555 | ||
| 7912 | 9년 전 | 404 | ||
| 7911 | 9년 전 | 351 | ||
| 7910 | 9년 전 | 397 | ||
| 7909 | 9년 전 | 495 | ||
| 7908 | 9년 전 | 409 | ||
| 7907 | 9년 전 | 356 | ||
| 7906 | 9년 전 | 375 | ||
| 7905 | 9년 전 | 354 | ||
| 7904 | 9년 전 | 340 | ||
| 7903 | 9년 전 | 338 | ||
| 7902 | 9년 전 | 546 | ||
| 7901 |
|
9년 전 | 725 | |
| 7900 | 9년 전 | 566 | ||
| 7899 | 9년 전 | 365 | ||
| 7898 | 9년 전 | 374 | ||
| 7897 | 9년 전 | 329 | ||
| 7896 | 9년 전 | 349 | ||
| 7895 | 9년 전 | 457 | ||
| 7894 | 9년 전 | 373 | ||
| 7893 | 9년 전 | 321 | ||
| 7892 | 9년 전 | 371 | ||
| 7891 | 9년 전 | 750 | ||
| 7890 | 9년 전 | 1185 | ||
| 7889 | 9년 전 | 741 | ||
| 7888 |
limsy1987
|
9년 전 | 536 | |
| 7887 | 9년 전 | 533 | ||
| 7886 | 9년 전 | 421 | ||
| 7885 | 9년 전 | 391 | ||
| 7884 | 9년 전 | 397 | ||
| 7883 | 9년 전 | 390 | ||
| 7882 | 9년 전 | 432 | ||
| 7881 | 9년 전 | 424 | ||
| 7880 | 9년 전 | 547 | ||
| 7879 | 9년 전 | 447 | ||
| 7878 | 9년 전 | 1204 | ||
| 7877 | 9년 전 | 738 | ||
| 7876 | 9년 전 | 469 | ||
| 7875 | 9년 전 | 546 | ||
| 7874 |
|
9년 전 | 797 | |
| 7873 | 9년 전 | 507 | ||
| 7872 | 9년 전 | 662 | ||
| 7871 | 9년 전 | 469 | ||
| 7870 | 9년 전 | 596 | ||
| 7869 | 9년 전 | 419 | ||
| 7868 | 9년 전 | 428 | ||
| 7867 | 9년 전 | 408 | ||
| 7866 | 9년 전 | 475 | ||
| 7865 | 9년 전 | 438 | ||
| 7864 | 9년 전 | 502 | ||
| 7863 | 9년 전 | 497 | ||
| 7862 | 9년 전 | 458 | ||
| 7861 | 9년 전 | 615 | ||
| 7860 | 9년 전 | 608 | ||
| 7859 | 9년 전 | 397 | ||
| 7858 | 9년 전 | 692 | ||
| 7857 | 9년 전 | 1057 | ||
| 7856 | 9년 전 | 506 | ||
| 7855 | 9년 전 | 729 | ||
| 7854 | 9년 전 | 719 | ||
| 7853 | 9년 전 | 569 | ||
| 7852 | 9년 전 | 498 | ||
| 7851 | 9년 전 | 491 | ||
| 7850 | 9년 전 | 574 | ||
| 7849 | 9년 전 | 351 | ||
| 7848 | 9년 전 | 400 | ||
| 7847 | 9년 전 | 634 | ||
| 7846 | 9년 전 | 442 | ||
| 7845 | 9년 전 | 401 | ||
| 7844 | 9년 전 | 384 | ||
| 7843 | 9년 전 | 400 | ||
| 7842 | 9년 전 | 386 | ||
| 7841 | 9년 전 | 373 | ||
| 7840 | 9년 전 | 389 | ||
| 7839 | 9년 전 | 424 | ||
| 7838 | 9년 전 | 506 | ||
| 7837 | 9년 전 | 343 | ||
| 7836 | 9년 전 | 389 | ||
| 7835 | 9년 전 | 459 | ||
| 7834 |
|
9년 전 | 1184 | |
| 7833 | 9년 전 | 408 | ||
| 7832 | 9년 전 | 403 | ||
| 7831 | 9년 전 | 543 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기