Day Logic - Multi-Arraywritten 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. Comments: (0) |
|