我創建小的統計數字,但有問題.. 我有魚,鑽機,誘餌和線從數據庫信息。如何避免if/elseif重複?
我想檢查每個可能的變化與此信息。 我的代碼如下所示:
if ((isset($_SESSION['fish_id'])) && (isset($_SESSION['rig_id'])) && (isset($_SESSION['bait_id'])) && (isset($_SESSION['line_id']))) {
echo '<img class="img-responsive" src="../assets/img/choose_fish.png">';
echo '<div class="list-notes"> <ul> <li class="name">';
echo 'FISH , RIG , BAIT , LINE';
echo '</li></ul></div>';
} elseif ((isset($_SESSION['fish_id'])) && (isset($_SESSION['rig_id'])) && (isset($_SESSION['bait_id'])) && (!isset($_SESSION['line_id']))) {
echo '<img class="img-responsive" src="../assets/img/choose_fish.png">';
echo '<div class="list-notes"> <ul> <li class="name">';
echo 'FISH , RIG , BAIT , *LINE*';
echo '</li></ul></div>';
} elseif ((isset($_SESSION['fish_id'])) && (isset($_SESSION['rig_id'])) && (!isset($_SESSION['bait_id'])) && (isset($_SESSION['line_id']))) {
echo '<img class="img-responsive" src="../assets/img/choose_fish.png">';
echo '<div class="list-notes"> <ul> <li class="name">';
echo 'FISH , RIG , *BAIT* , LINE';
echo '</li></ul></div>';
} elseif ((isset($_SESSION['fish_id'])) && (!isset($_SESSION['rig_id'])) && (isset($_SESSION['bait_id'])) && (isset($_SESSION['line_id']))) {
echo '<img class="img-responsive" src="../assets/img/choose_fish.png">';
echo '<div class="list-notes"> <ul> <li class="name">';
echo 'FISH , *RIG* , BAIT , LINE';
echo '</li></ul></div>';
} ((!isset($_SESSION['fish_id'])) && (isset($_SESSION['rig_id'])) && (isset($_SESSION['bait_id'])) && (isset($_SESSION['line_id']))) {
echo '<img class="img-responsive" src="../assets/img/choose_fish.png">';
echo '<div class="list-notes"> <ul> <li class="name">';
echo '*FISH* , RIG , BAIT , LINE';
echo '</li></ul></div>';
}
後,我需要檢查,如果魚不集和鑽機是不是集..等..
我怎樣才能避免這種情況重複?
@SashantPardeshi,是的,這就是爲什麼有一個字的警告(「值得商榷,如果它是有道理的四個固定項目」)。 –
是的你對:) –