PHP Arrays to set 2 variables

Discussion in 'PHP' started by sethyr, Jan 31, 2010.

  1. #1
    In this code I have a variable set to the Number of the week (1-52) and then a week type. I setup an array that has the week and set the type. I then put the week type variable into an if statement to output that type of week. Now what my problem is... How do I get the array to define the week type with the week number. Looking at the code might make help make more sense out of this.

    <?
    	$setday = date("l");
    	$setweek = date("W"); //GET WEEK NUMBERS
    	$a = "Today is an A Day";
    	$b = "Today is a B Day";
    	$c = "No School Today";
    	$d = "Tier 2 of OFYP";
    	$e = "Summer Break";
    	
    	// Week Type:
    	// EACH WEEK IS SET TO A CERTAIN TYPE.
    	// 1 = ABABA     2 = BABAB     3 = No School All Week     4 = Tier 2     5 = Summer Break
    	$week = array(
    		 1 => "3",
    	 	 2 => "2",
    		 3 => "1",
    		 4 => "1",
    		 5 => "2",
    		 6 => "1",
    		 7 => "2",
    		 8 => "1",
    		 9 => "2",
    		10 => "1",
    		11 => "2",
    		12 => "3", //SPRING BREAK
    		13 => "1",
    		14 => "2", //BAD WEATHER DAY
    		15 => "2", 
    		16 => "1",
    		17 => "2",
    		18 => "1",
    		19 => "2",
    		20 => "1",
    		21 => "2",
    		22 => "4", //TIER 2
    		23 => "4", //TIER 2
    		24 => "5", //SUMMER BREAK
    		25 => "5", //SUMMER BREAK
    		26 => "5", //SUMMER BREAK
    		27 => "5", //SUMMER BREAK
    		28 => "5", //SUMMER BREAK
    		29 => "5", //SUMMER BREAK
    		30 => "5", //SUMMER BREAK
    		31 => "5", //SUMMER BREAK
    		32 => "5", //SUMMER BREAK | LAST WEEK OF JULY
    		35 => "5",
    		36 => "1", //FIRST WEEK OF SCHOOL
    		);
    	
    
    	//Set Week Types
    	if     ($week == "1" && $setday == "Monday" || "Wednesday" || "Friday") { $day = $a; }	
    	elseif ($week == "1" && $setday == "Tuesday" || "Thursday") 			{ $day = $b; }
    	elseif ($week == "2" && $setday == "Monday" || "Wednesday" || "Friday") { $day = $b; }	
    	elseif ($week == "2" && $setday == "Tuesday" || "Thursday") 			{ $day = $a; }
    	elseif ($setday == "Saturday" || "Sunday" || $holiday) 					{ $day = $c; }
    	elseif ($week == "3")													{ $day = $c; }
    	elseif ($week == "4")													{ $day = $d; }
    	elseif ($week == "5")													{ $day = $e; }
    	echo $setday . "<br />" . $day; 
    
    ?>
    PHP:

     
    sethyr, Jan 31, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am having a hard time parsing this question. Can you give an example of the outcome you want?
     
    SmallPotatoes, Jan 31, 2010 IP
  3. sethyr

    sethyr Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Okay so in the array I have 1 through 36 which represent the weeks of the year that i have so far. Each of those weeks is set to a type. So for example type 1 is ABABA. So then when it's that week that type gets put into the if statement below. Then it conforms to that type. So If its Monday, Wednesday, or Thursday then it's an A day and then Tuesday and Thursday are B days. Then the next week it'll be Type 2, and so on. Im not sure how to put the week # and the week type together and put it into the if statement.
     
    sethyr, Jan 31, 2010 IP
  4. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I still don't really understand what you're saying, but perhaps this is useful:

    echo "<p>The type for the current week (#{$setweek}) is: {$week[$setweek]}</p>";
    PHP:
     
    SmallPotatoes, Jan 31, 2010 IP