°ªÀÌ ¹è¿ ¾È¿¡ Á¸ÀçÇÏ´ÂÁö È®ÀÎÇÏ´Â in arrayÇÔ¼ö |
|
|
 |
8³â Àü |
in_array
(PHP 4, PHP 5)
in_array — °ªÀÌ ¹è¿ ¾È¿¡ Á¸ÀçÇÏ´ÂÁö È®ÀÎ
¼³¸í
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
haystack ¿¡¼ needle À» ã½À´Ï´Ù.
Àμö
needle
ãÀ» °ª.
Note: needle ÀÌ ¹®ÀÚ¿À̸é, ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏ¿© ºñ±³ÇÕ´Ï´Ù.
haystack
¹è¿.
strict
¼¼¹ø° Àμö strict ¸¦ TRUE·Î ¼³Á¤Çϸé, in_array() ÇÔ¼ö´Â haystack ¾È¿¡¼ needle ÀÇ ÀÚ·áÇüµµ È®ÀÎÇÕ´Ï´Ù.
¹Ýȯ°ª
needle À» ¹è¿¿¡¼ ãÀ¸¸é TRUE¸¦, ¾Æ´Ï¸é FALSE¸¦ ¹ÝȯÇÕ´Ï´Ù.
º¯°æÁ¡
¹öÀü ¼³¸í
4.2.0 needle ÀÌ ¹è¿ÀÏ ¼ö ÀÖ½À´Ï´Ù.
¿¹Á¦
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()°¡ ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇϹǷΠµÎ¹ø° Á¶°ÇÀº ½ÇÆÐÇÏ°í, À§ ÇÁ·Î±×·¥Àº ´ÙÀ½À» Ãâ·ÂÇÕ´Ï´Ù:
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 |
|
̵̧ : 360 |
̵̧
¸ñ·Ï
|
|