loop not processing first element
Posted: Fri Jun 06, 2014 9:41 pm
My code is intended to display selected days of the week in a variety of languages, with the week starting on Monday. Because November 2014 starts on a Monday, I use it to define the days, so 246 parsed should be Tuesday Thursday Saturday. The problem is that my code is dropping the first day of the selection. I have set the variable $days to 257, which should return "Tuesday, Friday, Sunday" but instead returns just "Friday, Sunday." Code follows:
Code: Select all
date_default_timezone_set('America/Los_Angeles');
$formatter = new IntlDateFormatter(en, IntlDateFormatter::LONG, NULL, 'America/Los_Angeles', NULL, "EEEE");
$days='257';
if ($days > 0) {
$datefordays= new DateTime("2014-09-01");
$dayformat=$formatter->format($datefordays);
for ($i=1; $i < 8;$i++){
$dayformat=$formatter->format($datefordays);
$dayformat = ($language_selected='en')? $dayformat."s $i " : $dayformat;
$dayz.= strpos(strval($days), strval($i))? " $dayformat," : NULL;
$datefordays->modify('+ 1 day');
}
$day = substr_replace($dayz,'',-1);
}
echo $day;