switch문을 축약시킬 수 없을까요?
본문
제가 개발자가 아니라 언어를 잘 몰라서;;;
겨우겨우 끼워 맞춘 코드를 회원님이 도와주셔서 원하는 대로 완성했는데요.
현재 위치를 넣으려고 하니 1dep가 나오질 않아서 머리를 굴린게 다 만들어보자해서 시작했더니 너무 길어졌어요.
아래 코드를 좀 축약시킬 방법은 없을까요?
<!-- Board Page Top //-->
<?php if (!defined("_INDEX_")) { // 각 게시판 페이지에만 실행
switch($bo_table) {
case "space" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>설계자료</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "elements" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>설계자료</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "cad" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>설계자료</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "concept" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>디자인자료</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "proposal" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>디자인자료</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "business" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>시공자료</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "document" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>시공자료</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "dictionary" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "talk" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>커뮤니티</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "request" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>커뮤니티</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
case "upload" : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-home fa-fw"></i>커뮤니티</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php break;
default : ?>
<div id="container">
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
<?php } // End of switch
} ?>
<!--// Board Page Top -->
!-->
답변 1
$position = array('space' => '설계자료','proposal' => '디자인자료','business' => '시공자료');
foreach ($position as $key => $val) {
if ($bo_table == $key) {
$p = $val;
}
}
?>
<ul>
<li><i class="fas fa-home fa-fw"></i>HOME</li>
<?php if($p) { ?><li><i class="fas fa-home fa-fw"></i><?php echo $p ?></li><?php } ?>
<li><i class="fas fa-chevron-right fa-fw"></i><?php echo get_head_title($g5['title']); ?></li>
</ul>
답변을 작성하시기 전에 로그인 해주세요.