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.


  • Pages

  • Latest Pins on Pinterest

    • Follow Me on Pinterest

  • Quilting Projects I Want to Make

    • quilt kits black and gray - Google Search

    • How To Make A Quillow. One of my aunts made me one as a high school graduation gift. I wore it out and miss it!

    • Cute Cathedral Window by Pitter Putter Stitch. I'm really wanting to try the cathedral window quilt block and this one is so so pretty!

    • How about a modern I Spy quilt? This pattern uses a total of 51- 5" I Spy squares in the following colors: ...

    • Usando os presentes fofos !

    • My pdf patterns  are available  for purchase from my online Etsy shop here . Wholesale printed patterns are only available directly from m...

    • Arrowhead Quilt PDF Pattern — Initial K Studio

    • Dimension designed by Nydia Kehnle. Features #konacotton. Pattern available for purchase (nydiakehnle.bigca...).

    • Follow Me on Pinterest