knox203 Posted May 6, 2008 Share Posted May 6, 2008 Could someone tell me how I can list the values from this array? I want them to appear inside a drop down list... I can print out the array as a whole with print_r() but I need individual values. Thanks! <? /** * Function used to find the dates of specific days between * two different dates. So, if you want to find all the * mondays and all the wednesdays between 2 dates, this * function is right for you. * * @param string $startDate e.g. 2007-01-31 * @param string $endDate e.g. 2007-12-31 * @param csv string $days e.g. 'Su,M,T,W,TH,F,S'; * @return array */ $postmonth = $_POST['month']; $startDate = "2008-01-01"; $endDate = "2008-01-31"; $days = 'M'; function getDaysBetween($startDate, $endDate, $days) { $days = explode(',', $days); $dates = array(); foreach($days as $day) { $newDate = $startDate; switch ($day){ case 'Sun': $day = 'Sun'; break; case 'M': $day = 'Mon'; break; case 'Tue': $day = 'Tue'; break; case 'W': $day = 'Wed'; break; case 'Thu': $day = 'Thu'; break; case 'F'; $day = 'Fri'; break; case 'Sat': $day = 'Sat'; break; default: continue 2; } $curtime = strtotime("next $day", strtotime($startDate)); $endtime = strtotime($endDate); while($curtime <= $endtime) { $dates[] = date('Y-m-d', $curtime); $curtime = strtotime("next 2 $day", $curtime); } } $dates = array_unique($dates); sort($dates); return $dates; } $dates = getDaysBetween($startDate, $endDate, $days); ?> Link to comment https://forums.phpfreaks.com/topic/104377-echoing-array-values-from-a-function-in-a-while-loop/ Share on other sites More sharing options...
knox203 Posted May 6, 2008 Author Share Posted May 6, 2008 Bump? Link to comment https://forums.phpfreaks.com/topic/104377-echoing-array-values-from-a-function-in-a-while-loop/#findComment-534421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.