My collection of things.

jKafer on the Net

May 25th, 2011 at 7:17 pm

php Multidimensional arrays

Lately I have been working on some small snippets of code to automate tasks I do often, yet not often. I do them so rarely that I forget how I did it the last time. But yet, I have to do it every year – well around every holiday at least.

I take care of an international webpage for a customer service department. I need to post the holiday shutdown schedule when we come close to a holiday. Luckily there are only 6 of them. So to automate the message I finally sat down and wrote this snippet to automatically display the message about a closing day 14 days before the holiday – it’s more reliable that I am to update itself.

Is it the best way? Maybe, maybe not.
Is it the only way? Absolutely not.
But this works for what I need. I update it once a year when our company releases it’s shutdown schedule.

I am using a multidimensional array, I’ve set the key for the 2nd level.

Here it is:

<?
$tToday = date("Y-m-d");
//array structure:   array( startdate, enddate, displaydate, holiday);
$wSched = array(0 => array( '2012-1-1', '2012-1-2', '2011-12-18', 'New Years'),
    1 => array( '2011-5-30','2011-5-30', '2011-5-16', 'Memorial Day'),
    2 => array( '2011-7-4', '2011-7-4', '2011-6-20', 'July 4th'),
    3 => array( '2011-9-5', '2011-9-5', '2011-8-22', 'Labor Day'),
    4 => array( '2011-11-24', '2011-11-28', '2011-11-10', 'Thanksgiving'),
    5 => array( '2011-12-26', '2011-12-27', '2011-12-12', 'Christmas'));

$tMsg = "<h2>ATTENTION</h2>";
$tMsgL = strlen($tMsg);
asort($wSched);
 for ($col=0; $col <6; $col++)
  { 
   if(strtotime($tToday) >= strtotime($wSched[$col][2]) && strtotime($tToday) <=
strtotime($wSched[$col][1]) )
    {          
      $tMsg.= "<p>Mate will be closed on <br />".date("D, F j, Y",
strtotime($wSched[$col][0]));
      if ( strtotime($wSched[$col][1]) != strtotime($wSched[$col][0]) )  
         {
           $tMsg .= " thru ".date("D, F j, Y", strtotime($wSched[$col][1]));
         }
      $tMsg .= "<br /> in observation of ".$wSched[$col][3]." Holiday</p>";
    };  

  }; //end for

if (strlen($tMsg)> $tMsgL)
{
   print $tMsg;
};
?>

-

Comments are closed.


  • Count per Day

    • 4Visitors today:
    • 40Visitors per day:
    • 0Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • Blue Carolina Starburst Quilt {Free Pattern}

    • Well Texas Tumbleweeds got finished.  If you missed that, find it here.  So it’s time for a new UFO.  Earlier I had pulled Fair and Square but after I got the string triangles done, I left it…

    • 719 Likes, 25 Comments - David (@scfdavid) on Instagram: “Here’s my Blockheads block for Week 45 - Double Dutch - from my friend, Jo Morton! Thanks, Jo! All…”

    • Quilt patriotic Hidden Glorry reserved for Carrie by marytequilts

    • Tutorial - How to Get Perfect Centers

    • How to sew and trim half rectangle triangles (HRTs) - Kirsty of Bonjour Quilts

    • Center Point designed by Elise Lea for Robert Kaufman. Features Chalk and Charcoal by Jennifer Sampou, shipping to stores May 2018. Roll up friendly. FREE pattern available for download from robertkaufman.com May 2018. #FREEatrobertkaufmandotcom

    • A modern quilt blog focused on practical tutorials and quilting tips. Sharing traditionally pieced quilt patterns and lots of free quilt alongs.