Strange LOGIC Behavior...
| From: | Don Wieland | Date: | Fri, 05 Feb 2016 07:58:13 +0000 |
| Subject: | Strange LOGIC Behavior... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-325384@lists.php.net to get a copy of this message | ||
I have a echoed $_POST array which has theses values:
[s_date_start] => 2016-02-01
[s_date_start] => 2016-03-31
[s_int_tue] => 1
[s_int_thu] => 1
[s_int_sat] => 1
then I declare variables for the these post array values:
$this->s_date_start=$db->prepare_input($_POST['s_date_start']);
$this->s_date_end=$db->prepare_input($_POST['s_date_end'])
$this->s_int_mon=$db->prepare_input($_POST['s_int_mon']);
$this->s_int_tue=$db->prepare_input($_POST['s_int_tue']);
$this->s_int_wed=$db->prepare_input($_POST['s_int_wed']);
$this->s_int_thu=$db->prepare_input($_POST['s_int_thu']);
$this->s_int_fri=$db->prepare_input($_POST['s_int_fri']);
$this->s_int_sat=$db->prepare_input($_POST['s_int_sat']);
$this->s_int_sun=$db->prepare_input($_POST['s_int_sun']);
the prepare_input() functions guards against injections - produces proper values.
I am trying to add some logic to build arrays of days and dates based on the options:
$tDate = $this->s_date_start;
$eDate = $this->s_date_end;
$days = '';
if($this->s_int_mon == '1') $days[] = '1';
if($this->s_int_tue == '1') $days[] = '2';
if($this->s_int_wed == '1') $days[] = '3';
if($this->s_int_thu == '1') $days[] = '4';
if($this->s_int_fri == '1') $days[] = '5';
if($this->s_int_sat == '1') $days[] = '6';
if($this->s_int_sun == '1') $days[] = '0';
while (strtotime($tDate) <= strtotime($eDate)) {
if(in_array(date('w', strtotime($tDate)), $days)) $date_array[] = $tDate;
$tDdate = date ("Y-m-d", strtotime("+1 day", strtotime($tDate)));
}
This is giving me ALL THE DAYS (60 days) instead of weekdays == ‘1’
Can anyone enlighten me on what I am doing incorrect? Thanks!
Don Wieland