Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:23:51+00:00 2026-05-31T04:23:51+00:00

Instead of having code like the following: if ( $Boss1 ==1) { $Boss1_holder =

  • 0

Instead of having code like the following:

if ( $Boss1 ==1)
            {
                $Boss1_holder = $tick;
            }

            else if ( $Boss1 ==0)
            {
                $Boss1_holder = $cross;
            }



            if ( $Boss2 ==1)
            {
                $Boss2_holder = $tick;
            }
            else if ( $Boss2 ==0)
            {
                $Boss2_holder = $cross;
            }


            if ( $Boss3 ==1)
            {
                $Boss3_holder = $tick;
            }
            else if ( $Boss3 ==0)
            {
                $Boss3_holder = $cross;
            }


            if ( $Boss4 ==1)
            {
                $Boss4_holder = $tick;
            }
            else if ( $Boss4 ==0)
            {
                $Boss4_holder = $cross;
            }

Can i instead do something like this:

                $i = 1;
            while ($i <= 4) 
            {
                if ( $Boss[$i] ==1)
                {
                    $boss_holder[$i] = $tick;
                }

                else if ( $Boss[$i] ==0)
                {
                    $boss_holder[$i] = $cross;
                }

            }

I’m not entirely sure how to do it. At the moment if only have 4 sets of if else statements but my program later would require about 30 of them and i would rather having something like my second block that will reduce the amount of lines required. Am i on the right track. I think the $boss_holder[$i] part is incorrect as [i] would be part of an array? however i dont know how to write this correctly. I have looked on the php manual page but a lot of the examples are some what complex and go above the scope i need.

To clarify if i have explanined this poorly. I am trying to add a value onto the end of the variable $boss_holder that increments with the while loop counter

    $Boss1_holder = '';
$Boss2_holder = '';
$Boss3_holder = '';
$Boss4_holder = '';
$Boss5_holder = '';
$Boss6_holder = '';
$Boss7_holder = '';
$Boss8_holder = '';
$Boss9_holder = '';
$Boss10_holder = '';
$Boss11_holder = '';
$Boss12_holder = '';
$Boss13_holder = '';
$Boss14_holder = '';
$Boss15_holder = '';
$completed1 = 0;
$completed2 = 0;
$completed3 = 0;
$counter = 0;
$tick ='&nbsp;<img src="/styles/subsilver2/theme/images/soap/tick.png">';
$cross ='&nbsp;<img src="/styles/subsilver2/theme/images/soap/cross.png">';

class checks
{

private $addthemup1;
private $addthemup2;
private $addthemup3;

public function checkBosses($Boss1, $Boss2, $Boss3, $Boss4, $Boss5, $Boss6, $Boss7, $Boss8, $Boss9, $Boss10, $Boss11, $Boss12, $Boss13, $Boss14, $Boss15)
{
    global  $tick, $cross, $completed1, $completed2, $completed3, $Boss1_holder, $Boss2_holder, $Boss3_holder, $Boss4_holder, $Boss5_holder, $Boss6_holder, $Boss7_holder, $Boss8_holder, $Boss9_holder, $Boss10_holder, $Boss11_holder, $Boss12_holder, $Boss13_holder, $Boss14_holder, $Boss15_holder;

    $addthemup1 = $Boss1 + $Boss2 + $Boss3 + $Boss4 + $Boss5;
    $addthemup2 = $Boss6 + $Boss7 + $Boss8 + $Boss9 + $Boss10;
    $addthemup3 = $Boss11 + $Boss12 + $Boss13 + $Boss14 + $Boss15;

    switch ($addthemup1)
            {
                case "5":
                $completed1 = $tick;
                break;

                case "4":
                $completed1 ='4/5';
                break;  

                case "3":
                $completed1 ='3/5';
                break;  

                case "2":
                $completed1 ='2/5';
                break;

                case "1":
                $completed1 ='1/5';
                break;  

                case "0":
                $completed1 ='0/5';
                break;  
            }
    switch ($addthemup2)
            {
                case "5":
                $completed2 = $tick;
                break;

                case "4":
                $completed2 ='4/5';
                break;  

                case "3":
                $completed2 ='3/5';
                break;  

                case "2":
                $completed2 ='2/5';
                break;

                case "1":
                $completed2 ='1/5';
                break;  

                case "0":
                $completed2 ='0/5';
                break;  
            }
    switch ($addthemup3)
            {
                case "5":
                $completed3 = $tick;
                break;

                case "4":
                $completed3 ='4/5';
                break;  

                case "3":
                $completed3 ='3/5';
                break;  

                case "2":
                $completed3 ='2/5';
                break;

                case "1":
                $completed3 ='1/5';
                break;  

                case "0":
                $completed3 ='0/5';
                break;  
            }




            if ( $Boss1 ==1)
            {
                $Boss1_holder = $tick;
            }

            else if ( $Boss1 ==0)
            {
                $Boss1_holder = $cross;
            }



            if ( $Boss2 ==1)
            {
                $Boss2_holder = $tick;
            }
            else if ( $Boss2 ==0)
            {
                $Boss2_holder = $cross;
            }


            if ( $Boss3 ==1)
            {
                $Boss3_holder = $tick;
            }
            else if ( $Boss3 ==0)
            {
                $Boss3_holder = $cross;
            }


            if ( $Boss4 ==1)
            {
                $Boss4_holder = $tick;
            }
            else if ( $Boss4 ==0)
            {
                $Boss4_holder = $cross;
            }


            if ( $Boss5 ==1)
            {
                $Boss5_holder = $tick;
            }
            else if ( $Boss5 ==0)
            {
                $Boss5_holder = $cross;
            }

            if ( $Boss6 ==1)
            {
                $Boss6_holder = $tick;
            }

            else if ( $Boss6 ==0)
            {
                $Boss6_holder = $cross;
            }

            if ( $Boss7 ==1)
            {
                $Boss7_holder = $tick;
            }
            else if ( $Boss7 ==0)
            {
                $Boss7_holder = $cross;
            }


            if ( $Boss8 ==1)
            {
                $Boss8_holder = $tick;
            }
            else if ( $Boss8 ==0)
            {
                $Boss8_holder = $cross;
            }


            if ( $Boss9 ==1)
            {
                $Boss9_holder = $tick;
            }
            else if ( $Boss9 ==0)
            {
                $Boss9_holder = $cross;
            }


            if ( $Boss10 ==1)
            {
                $Boss10_holder = $tick;
            }
            else if ( $Boss10 ==0)
            {
                $Boss10_holder = $cross;
            }

            if ( $Boss11 ==1)
            {
                $Boss11_holder = $tick;
            }

            else if ( $Boss11 ==0)
            {
                $Boss11_holder = $cross;
            }



            if ( $Boss12 ==1)
            {
                $Boss12_holder = $tick;
            }
            else if ( $Boss12 ==0)
            {
                $Boss12_holder = $cross;
            }


            if ( $Boss13 ==1)
            {
                $Boss13_holder = $tick;
            }
            else if ( $Boss13 ==0)
            {
                $Boss13_holder = $cross;
            }


            if ( $Boss14 ==1)
            {
                $Boss14_holder = $tick;
            }
            else if ( $Boss14 ==0)
            {
                $Boss14_holder = $cross;
            }


            if ( $Boss15 ==1)
            {
                $Boss15_holder = $tick;
            }
            else if ( $Boss15 ==0)
            {
                $Boss15_holder = $cross;
            }


}

}

$sql = ‘SELECT * FROM raid_progression‘;

$result = $db->sql_query($sql);

  while ($row = $db->sql_fetchrow($result))
  {      
            $counter = $counter+1;

            $checker1 = new checks();   
            $checkResult1 = $checker1-> checkBosses($row['kp_em_no_bonethr'], $row['kp_em_no_foreman'], $row['kp_em_no_heavyfab'], $row['kp_em_no_jargsor'], $row['kp_em_no_kragga'],$row['kp_em_ha_bonethr'], $row['kp_em_ha_foreman'], $row['kp_em_ha_heavyfab'], $row['kp_em_ha_jargsor'], $row['kp_em_ha_kragga'],$row['kp_em_kn_bonethr'], $row['kp_em_kn_foreman'], $row['kp_em_kn_heavyfab'], $row['kp_em_kn_jargsor'], $row['kp_em_kn_kragga']);



            $template->assign_block_vars('raid_op', array(
            'VAR0' => $counter,
            'VAR1' => $row['guild_name'],
            'VAR2' => $row['guild_website'],
            'VAR3' => $row['server_name'],
            'VAR4' => $row['server_region'],
            'VAR5' => $row['faction_name'],
            'VAR6' => $completed1,
            'VAR7' => $Boss1_holder,
            'VAR8' => $Boss2_holder,
            'VAR9' => $Boss3_holder,
            'VAR10' => $Boss4_holder,
            'VAR11' => $Boss5_holder,
            'VAR12' => $Boss6_holder,
            'VAR13' => $Boss7_holder,
            'VAR14' => $Boss8_holder,
            'VAR15' => $Boss9_holder,
            'VAR16' => $Boss10_holder,
            'VAR17' => $Boss11_holder,
            'VAR18' => $Boss12_holder,
            'VAR19' => $Boss13_holder,
            'VAR20' => $Boss14_holder,
            'VAR21' => $Boss15_holder,
            'VAR22' => $completed2,
            'VAR23' => $completed3,
            ));






  }

  $db->sql_freeresult($result);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:23:52+00:00Added an answer on May 31, 2026 at 4:23 am

    There’s a few ways to do it…

    $boss = new array(1, 2, 3, 4);
    foreach($boss as $value){
        switch($value){
             case 1: 
                //do something
             break;
             case 2: 
                //something else;
             break;
        }
    }
    

    Would probably be how I wrote it.

    Edit: If you’re looking for clean code, you can do something like this:

    bosshandler.php:

    function doSomethingWithBoss($value){
        switch($value){
             case 1: 
                return "boss equals 1";
             break;
             case 2: 
                return "boss equals 2";
             break;
        }
    }
    

    Your script page:

    include bosshandler.php;
    $boss = new array(1, 2, 3, 4);
    foreach($boss as $value){
        echo doSomethingWithBoss($value);
    }
    

    Ok, trying again. I think I see what you’re asking now:

    You want to assign a variable so that your arrays match up. If you’re in $boss[1] you want to assign something to $boss_holder['1'], is that correct? If so, you don’t want to use a foreach array, as it can be somewhat unpredictable with arrays and the order in which it parses them.

    Instead, let’s use a for() loop, like so:

    $boss = new Array(1, 2, 3, 4);
    $boss_holder = new Array(); //empty
    $length = count($boss);
    //iterate through boss
    for($i = 1; $i < $length; $i++){
        if($boss[$i] == 1){
            $boss_holder[$i] = $tick;
        }elseif($boss[$i] == 2){
            $boss_holder[$i] = $cross;
        }
    }
    

    Edit again to reflect your full code:

    Use arrays. Refactor your code so that it uses arrays. If for some reason you absolutely cannot or will not use arrays, you can use PHP’s variable variables to accomplish what you’re looking for. It would look something like this:

    var $boss1_holder, $boss2_holder, $boss3_holder;
    for($i=1; $i> 4; $i++){
        $variableName = 'boss' . $i . '_holder';
        $$variableName = 1;
    }
    echo $boss2_holder; //returns 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Instead of having an add() method in the repository, I would like to overload
motivation: I would like to create a utility class so that instead of having
I am having the following code: @interface Room : NSObject { @protected NSMutableDictionary* mCustomProperties;
I'm having trouble with jquery and selectors using the following code: <div id=test></div> console.log($('#test'));
I am having issues with the following code in Scala import org.junit.Test import org.junit.Assert._
Instead of having to remember to initialize a simple 'C' structure, I might derive
Recently I used a class that inherits from a collection instead of having the
Constant height so just left/right images should be necessary instead of having 4+, right?
Is there a way to view the latest debug message instead of having to
In compiler design, why instead of having a caller or callee register saving arrangement,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.