비교연산자 질문 입니다. 정보
비교연산자 질문 입니다.본문
아래 소스는 bo_table 가 board1_1과 같으면 아래를 뿌려라 입니다.
<?
if($bo_table =="board1_1"){ //공지게시판일 때
include_once("$g4[path]/menu/learning.php");
}
?>
근데 bo_table 가 board2_2 일때도 아래를 뿌릴려면..
<?
if($bo_table =="board1_1"){ //공지게시판일 때
include_once("$g4[path]/menu/learning.php");
}
if($bo_table =="board2_2"){ //공지게시판일 때
include_once("$g4[path]/menu/learning.php");
}
?>
이렇게 if를 써줘야 되겠죠..
문제는 테이블이 20개가 넘는데..
다 이렇게 if문을 사용할 수 밖에 없는지 궁금합니다...
<?
if($bo_table =="board1_1"){ //공지게시판일 때
include_once("$g4[path]/menu/learning.php");
}
?>
근데 bo_table 가 board2_2 일때도 아래를 뿌릴려면..
<?
if($bo_table =="board1_1"){ //공지게시판일 때
include_once("$g4[path]/menu/learning.php");
}
if($bo_table =="board2_2"){ //공지게시판일 때
include_once("$g4[path]/menu/learning.php");
}
?>
이렇게 if를 써줘야 되겠죠..
문제는 테이블이 20개가 넘는데..
다 이렇게 if문을 사용할 수 밖에 없는지 궁금합니다...
댓글 전체
in_array나 정규표현식 등 여러방법이 있습니다.
if(in_array($bo_table, array('board1_1', 'board2_1', 'board3_1')) == true) echo include_once(xxx);
if(preg_match('/^board[0-9]_1$/', $bo_table) == true) include_once(xxx);
http://kr2.php.net/manual/kr/function.in-array.php
http://kr2.php.net/manual/kr/function.preg-match.php
...
if(in_array($bo_table, array('board1_1', 'board2_1', 'board3_1')) == true) echo include_once(xxx);
if(preg_match('/^board[0-9]_1$/', $bo_table) == true) include_once(xxx);
http://kr2.php.net/manual/kr/function.in-array.php
http://kr2.php.net/manual/kr/function.preg-match.php
...
<?
switch( $bo_table) {
case "board1_1":
case "board2_2":
case "board3_3":
include_once("$g4[path]/menu/learning.php");
}
switch( $bo_table) {
case "board1_1":
case "board2_2":
case "board3_3":
include_once("$g4[path]/menu/learning.php");
}
이프문 비교 연산자