웹프로그래밍/PHP
[php] in_array 배열에 값이 존재하는지 확인하기
타자치는 고선생
2022. 11. 21. 21:47
728x90
반응형
php in_array 함수를 통해 배열에 값이 존재하는지 확인할 수 있다.
<?php
$array = array("한국","중국","일본","미국");
if(in_array("한국",$array)) {
echo "한국이 포함되어 있습니다.";
}
if(in_array(array("한국","미국"),$array)) {
echo "한국과 미국이 포함되어 있습니다.";
}
?>
더보기
참고 :
https://www.php.net/manual/en/function.in-array.php
PHP: in_array - Manual
Loose checking returns some crazy, counter-intuitive results when used with certain arrays. It is completely correct behaviour, due to PHP's leniency on variable types, but in "real-life" is almost useless.The solution is to use the strict checking option.
www.php.net
728x90
반응형