We use cookies to improve our services and products. Please refer to our terms and privacy policy for more information. We DO NOT use 3rd Party cookies or tracking software. And We DO NOT sell data to 3rd party vendors. We value your privacy.



AboutBlogContactGallery

Log In   |   Sign Up

Pages

mobile_icon   Blog

mobile_icon   Animation

mobile_icon   Video

mobile_icon   Web Development

mobile_icon   Music

About

mobile_icon   Home

mobile_icon   About

mobile_icon   Contact

mobile_icon   Gallery

mobile_icon   Request Quote

Website Options

Reader
ON OFF

Side Ads
ON OFF

Bottom Ads
ON OFF











Day Logic - Multi-Array

written by: Michael Paul MacKillip
Reader Mode 
|



posted on: Sep 26, 2019



This is the logic sequence I used to return two 'day' arrays, that return values for M-S for tables looking back over the last week, with results populating from left to right and right to left. Results display as a single letter value M T W T F S S.

It is based on a number line going infinitely in opposite directions.

-9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9

9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9

The initial server request returns a numeric value which is translated into a letter value for the given day. This logic sequence returns two date arrays. One array displaying results right to left for the last week. And one array displaying left to right for the last week.

M T W T F S S

S S F T W T M


This is a small snippit of the basic formula



$day = date("w");
$t = "";

if (preg_match("/0/", $day)) {
$t = "S";
} else if (preg_match("/1/", $day)) {
$t = "M";
} else if (preg_match("/2/", $day)) {
$t = "T";
} else if (preg_match("/3/", $day)) {
$t = "W";
} else if (preg_match("/4/", $day)) {
$t = "Th";
} else if (preg_match("/5/", $day)) {
$t = "F";
} else if (preg_match("/6/", $day)) {
$t = "Sa";
} else if (preg_match("/7/", $day)) {
$t = "S";
}

echo "Today is ";
echo $t;




Below is an image of the example I was able to accomplish using php to help populate dynamic graphs using chart.js for the frontend display. With both charts looking over data for the last week for with displays, from left to right and right to left.


Logic Graph Picture

Comments: (0)









Need IT/Tech?
we can help