array search — ÁÖ¾îÁø °ªÀ¸·Î ¹è¿À» °Ë»öÇÏ¿© ¼º°ø½Ã ÇØ´çÇÏ´Â Å°¸¦ ¹Ýȯ |
|
|
![](icon/private_name/1.gif) |
13³â Àü |
mixed array_search ( mixed $needle , array $haystack [, bool $strict ] )
¨ç needle ÀÌ ¹®ÀÚ¿À̸é, ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏ¿© ºñ±³ÇÕ´Ï´Ù.
¨è ¹è¿¿¡¼ needle À» ãÀ¸¸é Å°¸¦ ¹ÝȯÇÏ°í, ¾Æ´Ï¸é FALSE¸¦ ¹ÝȯÇÕ´Ï´Ù.
¨é haystack ¿¡¼ needle À» µÎ ¹ø ÀÌ»ó ¹ß°ßÇϸé, óÀ½ ¸ÅÄ¡ÇÑ Å°¸¦ ¹ÝȯÇÕ´Ï´Ù.
¨ê ¸ÅÄ¡ÇÏ´Â ¸ðµç °ª¿¡ ´ëÇØ Å°¸¦ ¹Ýȯ¹ÞÀ¸·Á¸é, array_keys()¿¡ ¼±ÅÃÀûÀÎ search_value Àμö¸¦ »ç¿ëÇϽʽÿÀ.
¨ë ¼¼¹ø° Àμö strict ¸¦ TRUE·Î ¼³Á¤Çϸé, array_search() ÇÔ¼ö´Â haystack ¿¡¼ needle ÀÇ ÀÚ·áÇüµµ È®ÀÎÇÕ´Ï´Ù.
¨ì PHP 4.2.0 ÀÌÀü¿¡, array_search()´Â ½ÇÆнÿ¡ FALSE ´ë½Å NULLÀ» ¹ÝȯÇß½À´Ï´Ù.
¨í ÀÌ ÇÔ¼ö´Â ³í¸® FALSE¸¦ ¹ÝȯÇÏÁö¸¸, 0À̳ª "" µî, ³í¸® FALSE·Î Ãë±ÞÇÒ ¼ö ÀÖ´Â ´Ù¸¥ °ªÀ» ¹ÝȯÇÒ ¼ö ÀÖ½À´Ï´Ù.
¨î ÀÌ ÇÔ¼öÀÇ ¹Ýȯ°ªÀ» È®ÀÎÇÏ·Á¸é === ¿¬»êÀÚ¸¦ ÀÌ¿ëÇϽʽÿÀ.
[»ç¿ë¿¹]
<?
$main_category = "¼¿ï½Ã|ÀÎõ½Ã|ºÎ»ê½Ã|";
$sub_category = "°³²±¸^°ü¾Ç±¸^ÀºÆò±¸|°È±º^°è¾ç±¸^³²±¸|¿µµµ±¸^Áß±¸^ÇØ¿î´ë±¸";
$sca = "ÀÎõ½Ã";
$arr = explode("|", $main_category);
$arr1 = explode("|", $sub_category);
$key = array_search($sca, $arr);
$cate = explode("^", $arr1[$key]);
echo $key; // 1
var_dump($cate); // array(3) { [0]=> string(9) "°È±º" [1]=> string(9) "°è¾ç±¸" [2]=> string(6) "³²±¸" }
?>
http://docs.php.net/manual/kr/function.array-search.php |
|
̵̧ : 507 |
̵̧
¸ñ·Ï
|
|